For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > June 2005 > How to convert "([^"]*)" to ``$1''?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author How to convert "([^"]*)" to ``$1''?
Zeng Nan

2005-06-05, 8:55 am

Hi,

I'd like to convert a text file to tex. One thing I encounter is that
there are lots of dialogues, and I want to transform " " to `` ''
properly. I try to use s/"([^"]*)"/``$1"/gs but it doesn't work
correctly. Any ideas?

Regards,
--
Zeng Nan
Simple is Beautiful.
~~~~~~~~~~~~~~~~~~~~
PGP Key: http://hobbit.homeunix.org

Ing. Branislav Gerzo

2005-06-05, 8:55 am

Zeng Nan [ZN], on Sunday, June 5, 2005 at 16:20 (+0800) contributed
this to our collective wisdom:

ZN> I'd like to convert a text file to tex. One thing I encounter is that
ZN> there are lots of dialogues, and I want to transform " " to `` ''
ZN> properly. I try to use s/"([^"]*)"/``$1"/gs but it doesn't work
ZN> correctly. Any ideas?

try this:
s/"([^"]+)"/``$1''/gs

(untested)

--

...m8s, cu l8r, Brano.

[On what conclusion do you base your facts? ..Opinion?]


Peter Scott

2005-06-05, 3:56 pm

On Sun, 05 Jun 2005 12:30:34 +0200, Ing. Branislav Gerzo wrote:
> Zeng Nan [ZN], on Sunday, June 5, 2005 at 16:20 (+0800) contributed
> this to our collective wisdom:
>
> ZN> I'd like to convert a text file to tex. One thing I encounter is that
> ZN> there are lots of dialogues, and I want to transform " " to `` ''
> ZN> properly. I try to use s/"([^"]*)"/``$1"/gs but it doesn't work
> ZN> correctly. Any ideas?
>
> try this:
> s/"([^"]+)"/``$1''/gs
>
> (untested)


Note that the /s is pointless there; there is no . in the regex.

--
Peter Scott
http://www.perlmedic.com/
http://www.perldebugged.com/

Ing. Branislav Gerzo

2005-06-05, 3:56 pm

Peter Scott [PS], on Sunday, June 05, 2005 at 05:38 (-0700) has on
mind:

PS> Note that the /s is pointless there; there is no . in the regex.

umm, s/s/m/ ? :)

--

...m8s, cu l8r, Brano.

["If you don't pay the exorcist, are you Re-possessed??"]


Zeng Nan

2005-06-05, 8:55 pm

Thanks all. I have figured it out. I should have used `undef $/' at the
beginning so that the whole file is treated as a string.

--
Zeng Nan
Simple is Beautiful.
~~~~~~~~~~~~~~~~~~~~
PGP Key: http://hobbit.homeunix.org

Peter Scott

2005-06-06, 3:56 pm

On Sun, 05 Jun 2005 14:44:56 +0200, Ing. Branislav Gerzo wrote:
> Peter Scott [PS], on Sunday, June 05, 2005 at 05:38 (-0700) has on
> mind:
>
> PS> Note that the /s is pointless there; there is no . in the regex.
>
> umm, s/s/m/ ? :)


There is/was no ^ or $ used as an anchor in the regex either.

Care to try again? :-)

--
Peter Scott
http://www.perlmedic.com/
http://www.perldebugged.com/

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2009 codecomments.com