Found at: http://publish.ez.no/article/articleprint/65/ |
Larger Regular Expressions |
Warning: The regular expressions contained in this article are of some length and quite illegible to the inexperienced. They can, however, be extremely useful and time-saving if you are trying to add structure to or search through large text documents. Proceed with caution.
<td><span style='font:times;align:center;color:blue'>Some blue text</td> |
<td><font color="blue">Some blue text</font></td> |
sed -e :a -e "s/\(<span[ \t\n\r]*style='.*color:\)\([a-z]*\)\(.*'>\)\([^<]*\)/<font color=\"\ 2\">\ 4<font>/g; /</N; //ba" old.xml > new.xml |
sed -e :a -e "s/search-text/replace-text/g; /</N; //ba" old.xml > new.xml |
\(<span[ \t\n\r]*style='.*color:\) |
\([a-z]*\) |
\(.*'>\) |
\([^<]*\) |
<font color=\"\ 2\">\ 4<font> |
#!/usr/bin/perl
$inputfile = $ARGV[0];
$outputfile = ">$ARGV[1]";
$docstring = "";
open( INPUT, $inputfile ) or die "Error while opening $inputfile: $!\n";
while( <INPUT> )
{
$docstring = $docstring . $_;
}
close INPUT;
$docstring =~ s/(<span[\s]*style=\'.*color:)([a-z]*)(.*\'>)([^<]*)/<font color=\"$ 2\">$ 4<font>/g
open( OUTPUT, $outputfile ) or die "Error while opening $outputfile: $!\n";
print OUTPUT $docstring;
close OUTPUT;
|