Regex, how do I replace quotation pairs into <LI> & </LI>?

Discussion in 'Perl Misc' started by Kelvin, Oct 21, 2004.

  1. Kelvin

    Kelvin Guest

    Basically, my texts consists of normal text stream and some quotations.

    This is my text stream, and inside "this streams" there are some "quotation
    pairs"
    which are to be replaced like this: <LI>this streams</LI> for formatting in
    HTML.

    Tried ___s/\".*?\"/<li>.*?<\/li>/g;___ but not working.

    Thanks.
    Kelvin
     
    Kelvin, Oct 21, 2004
    #1
    1. Advertising

  2. Kelvin wrote:
    > Basically, my texts consists of normal text stream and some
    > quotations.
    >
    > This is my text stream, and inside "this streams" there are some
    > "quotation pairs" which are to be replaced like this:
    > <LI>this streams</LI> for formatting in HTML.
    >
    > Tried ___s/\".*?\"/<li>.*?<\/li>/g;___ but not working.

    -------------------------^^^

    Please study the description of the s/// operator in "perldoc perlop" -
    Don't just guess!

    Maybe this is what you want:

    s/\"(.*?)\"/<li>$1<\/li>/gs;

    If not, please post a short, self-contained but *complete* program
    including sample data that illustrates what it is you are trying to do.

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
     
    Gunnar Hjalmarsson, Oct 21, 2004
    #2
    1. Advertising

  3. Kelvin

    Tore Aursand Guest

    On Thu, 21 Oct 2004 18:27:05 +0800, Kelvin wrote:
    > s/\".*?\"/<li>.*?<\/li>/g;


    No need to escape those "-characters, AFAIK. And you don't want to
    replace .*? above with - uhm - the regular expression .*?, do you?

    Untested, but I think something like this should do it;

    s,"(.*?)",<li>$1</li>,g;

    Please read these:

    perldoc perlretut
    perldoc perlre


    --
    Tore Aursand <>
    "Time only seems to matter when it's running out." (Peter Strup)
     
    Tore Aursand, Oct 21, 2004
    #3
  4. [ There IS NO comp.lang.perl newsgroup, it was removed MANY YEARS ago.
    If your news server carries it, then your server is poorly maintained.
    There is nothing about modules in your post, please do not make
    off-topic posts!

    Newsgroups trimmed, Followups set.
    ]


    Kelvin <> wrote:


    > This is my text stream, and inside "this streams" there are some "quotation
    > pairs"
    > which are to be replaced like this: <LI>this streams</LI> for formatting in
    > HTML.
    >
    > Tried ___s/\".*?\"/<li>.*?<\/li>/g;___

    ^^ ^^
    ^^ ^^

    I thought you said <LI></LI>? That isn't what you have there...


    > but not working.



    You need to capture the element's content so that you can put
    it back in. You use parenthesis to capture in regexes.

    Double quotes are not meta in regexes, so you don't need to backslash them.

    If you choose an alternate delimiter, then you won't need to
    backslash the / either.


    s#"(.*?)"#<LI>$1</LI>#g;


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Oct 21, 2004
    #4
  5. Kelvin

    Gerhard M Guest

    "Kelvin" <> wrote in message news:<41778d70$>...
    > Tried ___s/\".*?\"/<li>.*?<\/li>/g;___ but not working.


    hi kevin

    try
    s#"([^"]*)"#<li>$1</$1>#g

    matches " (any text but quotes) "
    and places (any text..) between <li> and </li>

    gerhard
     
    Gerhard M, Oct 21, 2004
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kelvin
    Replies:
    3
    Views:
    518
    Gerhard M
    Oct 21, 2004
  2. Enjoy Life

    Replace function for double quotation mark.

    Enjoy Life, Apr 14, 2004, in forum: ASP General
    Replies:
    33
    Views:
    528
    Ray at
    Apr 15, 2004
  3. Johan Martinez
    Replies:
    3
    Views:
    293
    Johan Martinez
    May 22, 2011
  4. Scott Bass
    Replies:
    10
    Views:
    232
    Brian McCauley
    May 30, 2005
  5. Tim
    Replies:
    4
    Views:
    625
    Jukka K. Korpela
    Nov 4, 2011
Loading...

Share This Page