Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Regex, how do I replace quotation pairs into <LI> & </LI>?

Reply
Thread Tools

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

 
 
Kelvin
Guest
Posts: n/a
 
      10-21-2004
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






 
Reply With Quote
 
 
 
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      10-21-2004
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
 
Reply With Quote
 
 
 
 
Tore Aursand
Guest
Posts: n/a
 
      10-21-2004
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 <(E-Mail Removed)>
"Time only seems to matter when it's running out." (Peter Strup)
 
Reply With Quote
 
Tad McClellan
Guest
Posts: n/a
 
      10-21-2004

[ 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 <(E-Mail Removed)> 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
http://www.velocityreviews.com/forums/(E-Mail Removed) Perl programming
Fort Worth, Texas
 
Reply With Quote
 
Gerhard M
Guest
Posts: n/a
 
      10-21-2004
"Kelvin" <(E-Mail Removed)> wrote in message news:<41778d70$(E-Mail Removed)>...
> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
basic Q on enclosing curly quotation/quot characters into strings Tim Javascript 4 11-04-2011 09:50 PM
replace lines in a file using hash key-value pairs Johan Martinez Ruby 3 05-22-2011 03:07 AM
Regex, how do I replace quotation pairs into <LI> & </LI>? Kelvin Perl 3 10-21-2004 04:56 PM
Replace function for double quotation mark. Enjoy Life ASP General 33 04-15-2004 01:28 PM



Advertisments