batkins has asked for the wisdom of the Perl Monks concerning the following question:
i'm trying to write a regular expression that will replace all single quotes (') not contained in <%...%> tags with a separate string. i've been trying for some time now and feel like a moron for not being able to get it. here's what i've come up with:
s/(%>.*)'(.*<%)/${1}test$2/g;
it even seems to work in test cases. but when i apply it to this file:
it doesn't do anything. any idea why?"Avert thine eyes, lest ye be stricken with coolness." (from the origi +nal batkins web site, dated April 8, 2002 )<br><br> <a href="http://batkins.com/forum/YaBB.pl">Enter the batkins forum</a> + - it's the place to be. <br><br> batkins.com is best viewed from the Hubble Telescope. <br><br> <hr> <font size="+1"><b><u>the batkins weblog - it's nature's candy</u></b> +</font> <br><br> <% # news my @news = split(/%%/, slurp("$DAT/news")); my $bit; my $i; for($i = 0; $i < 10; $i++) { $bit = "<b>$news[$i]</b><br>" . $news[$i + 1] . "<p>"; print $bit; $i++; } %> <a href="/main/news.pl">View the rest of the weblog (<% print scalar(@ +news) - $i; %> more entries)</a> <p> <font face="-2"><a href="/main/all.pl">the batkins directory</a></font +>
thanks for your help and let me know if you need any more info.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: silly regex question
by chromatic (Archbishop) on Jan 19, 2003 at 00:39 UTC | |
Re: silly regex question
by pg (Canon) on Jan 19, 2003 at 02:28 UTC | |
Re: silly regex question
by bart (Canon) on Jan 19, 2003 at 10:24 UTC | |
Re: silly regex question
by Abigail-II (Bishop) on Jan 19, 2003 at 15:27 UTC | |
Re: silly regex question
by I0 (Priest) on Jan 19, 2003 at 06:38 UTC | |
Re: silly regex question
by Anonymous Monk on Jan 19, 2003 at 03:41 UTC | |
Re: silly regex question
by batkins (Chaplain) on Jan 19, 2003 at 04:05 UTC |