the_0ne has asked for the wisdom of the Perl Monks concerning the following question:
Here's the output I am getting...$foo = "<italic>Here's a <bold>larger<normal> paragraph, <italic>where + I'm<norma l> going to <bold>bold some <italic>"; print "\nfoo before:\n$foo\n\n"; #foo.gsub!(/(?<=<italic>)(?<!<normal>)(.*?)<bold>/, '\1<bold-italic>') $foo =~ s/(?<=<italic>)(?<!<normal>)(.*?)<bold>/\1<bold-italic>/g; print "foo after:\n$foo\n";
Notice the second <bold> is being replaced with <bold-italic>. By the regex (at least I think I have the regex right) the second bold *should not* be replaced since I perform a look-behind for <normal>. If <normal> is between the <italic> and the <bold>, then the <bold> should be left alone. At least this is what I am trying to get at.# Output is... # <italic>Here's a <bold-italic>larger<normal> paragraph, <italic>wher +e I'm<normal> going to <bold-italic>bold some <italic>
Notice the second <bold> is not replaced.# However, should be... # <italic>Here's a <bold-italic>larger<normal> paragraph, <italic>wher +e I'm<normal> going to <bold>bold some <italic>
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Regex look-behind problem.
by ikegami (Patriarch) on Jul 12, 2007 at 22:43 UTC | |
by the_0ne (Pilgrim) on Jul 12, 2007 at 23:53 UTC | |
|
Re: Regex look-behind problem.
by runrig (Abbot) on Jul 12, 2007 at 21:30 UTC |