in reply to Re^6: Negating a regexp
in thread Negating a regexp
Actually that is a lot simpler to solve assuming one "element" per line:
use warnings; use strict; while (my $line = <DATA>) { # Assume one "element" per line if ($line =~ /<(\w+)>(.*?)<\/\1>/) { (my $midstr = $2) =~ tr/<>/[]/; $line = "<$1>$midstr</$1>\n"; } print $line; } __DATA__ <sometag> my data here </sometag> <anothertag> further text </anothertag> <furthertag> not good as contains <this> in angle brackets </furtherta +g> <byetag> another possibility is <more> <than> one <angle pairs> in her +e </byetag>
Prints:
<sometag> my data here </sometag> <anothertag> further text </anothertag> <furthertag> not good as contains [this] in angle brackets </furtherta +g> <byetag> another possibility is [more] [than] one [angle pairs] in her +e </byetag>
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^8: Negating a regexp
by jxh (Acolyte) on Feb 01, 2006 at 11:04 UTC |