Here's one way
#!/bin/perl5 use strict; use warnings; use HTML::TokeParser; my $str = q|<img src=\"test.jpg\"> highlight the word <img src=\"word. +jpg\">|; my $tp = HTML::TokeParser->new(\$str) or die "Couldn't parse $str: $!"; $tp->unbroken_text(1); my ($html, $start); while (my $tag = $tp->get_token) { if ($tag->[0] eq 'T'){ my $t = $tag->[1]; $t =~ s|word|<b>WORD</b>|g; $html .= $t; } else{ $html .= $tag->[4] if $tag->[0] eq 'S'; $html .= $tag->[1] if $tag->[0] eq 'C'; $html .= $tag->[2] if $tag->[0] eq 'E'; } } print "$html\n"; __DATA__ ---------- Capture Output ---------- > "C:\Perl\bin\perl.exe" parse_str.pl <img src=\"test.jpg\"> highlight the <b>WORD</b> <img src=\"word.jpg\" +> > Terminated with exit code 0.
In reply to Re: Replacing text NOT in an HTML tag
by wfsp
in thread Replacing text NOT in an HTML tag
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |