in reply to Re^4: Negating a regexp
in thread Negating a regexp
This violates your "no code" premise, but if your tags are all on one line, this seems reasonably robust and should be fairly efficient.
#! perl -sw use strict; while( <DATA> ) { s[^(<([^>]+?)>)(.*)(</\2>)]{ (my $x = $3) =~ tr[<>][[]]; "$1$x$4"; }e; print; } __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> <a tag with spaces> and content containing a false </a tag with spaces +> and a real </a tag with spaces>
Produces
C:\Perl\test>junk2 <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> <a tag with spaces> and content containing a false [/a tag with spaces +] and a real </a tag with spaces>
Of course, it doesn't attempt to deal with attributes, or multi-line elements or nested tags or any of that good stuff.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^6: Negating a regexp
by jxh (Acolyte) on Feb 02, 2006 at 11:09 UTC |