[luau] Perl String Question
Brian McSheehy
brian at proservicepeo.com
Thu Mar 25 16:34:40 PST 2004
Cody,
This is not entirely correct...
$string =~ s\(<b>|</b>)\\;
In this situation, /(string1|string2)/ perl looks for a match of either occurence of "string1" and "string2" per line. If "string1" is found, then perl will never search for "string2" on the same line. So when you run it only the first <b> tag will be removed and never the second</b>. In order to fix it a "g" would need to be added to the last "\" to tell perl not to stop searching after the first match is found. So...
$string =~ s\(<b>|</b>)\\g;
would work.
However, alternation in regex is resource expensive and should be avoided if at all possible in complex operations.
man perlre is great for a quick reference ;)
--Brian
----- Original Message -----
From: Taylor Cody L. Contr 502 AOS/PETS
To: luau at videl.ics.hawaii.edu
Sent: Thursday, March 25, 2004 8:14 AM
Subject: RE: [luau] Perl String Question
It looks like you already have your answer but since my friend replied I figured I would forward it on. -Cody
-----Original Message-----
From: Paul
$string =~ s\(<b>|</b>)\\;
FYI -
Normally those backslashes would be forward slashes, but since his
search string contains forward slashes, you can use another symbol to
keep perl from getting confused. For instance, I could have wrote
s*(<b>|</b>)** instead and it would have meant the same thing.
-----Original Message-----
From: Matthew John Darnell [mailto:mdarnell at servpac.com]
Sent: Wednesday, March 24, 2004 5:48 PM
To: luau at videl.ics.hawaii.edu
Subject: [luau] Perl String Question
Aloha,
If I have a string "<b>Yo ho ho and a bottle of rum</b>" is there an elegant way to eliminate the '<b>' & '</b>'?
It would also need to return nothing for the string "<b></b>"
I could hack something up, but I am thinking it could be accomplished in one line of code. I am sure there is more than one way to do it.
As you probably guessed, I am parsing a web page.
-Matt
------------------------------------------------------------------------------
_______________________________________________
LUAU mailing list
LUAU at lists.hosef.org
http://lists.hosef.org/cgi-bin/mailman/listinfo/luau
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freesoftwarehawaii.org/pipermail/luau-freesoftwarehawaii.org/attachments/20040325/9b11c061/attachment-0001.htm>
More information about the LUAU
mailing list