in reply to regex: Need help substituting
As toolic said, use an XML parser. But, in general terms, when I want to use a regex to change an unknown chunk of text that sits between two known chunks of text, I do it backwards from what you tried to do here. Instead of capturing the part I want to replace, I capture the parts I want to keep, and keep them. For instance:
$string = 'blah blah blah <some_sort_of_tag>CHANGE ME</some_sort_of_ta +g> blah blah blah'; $newtext = 'I AM NEW'; $string =~ s|^(.*<some_sort_of_tag>).+(</some_sort_of_tag>.*)$|$1$newt +ext$2|;
Aaron B.
My Woefully Neglected Blog, where I occasionally mention Perl.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: regex: Need help substituting
by the_perl (Initiate) on Apr 08, 2012 at 07:36 UTC | |
by Joe_ (Beadle) on Apr 08, 2012 at 13:57 UTC | |
by the_perl (Initiate) on Apr 09, 2012 at 14:36 UTC | |
by Joe_ (Beadle) on Apr 09, 2012 at 20:27 UTC |