... not restricted to a particular list of html codes ...
I'm not sure that's really such a good idea (it should be easy to get a list of all HTML entities you could possibly be interested in), but here's a generalization:
>perl -wMstrict -le "my $bad = 'x &foo;xx;yz;qwe; y &de;fghj;h; z &>< y lt;gt; z'; print qq{'$bad'}; ;; my $tity = qr{ [[:alpha:]]+ ; }xms; ;; (my $fixed = $bad) =~ s{ (?: (?: \G (?<! \A)) | &) $tity \K (?= $tity) } '&'xmsg; print qq{'$fixed'}; " 'x &foo;xx;yz;qwe; y &de;fghj;h; z &>< y lt;gt; z' 'x &foo;&xx;&yz;&qwe; y &de;&fghj;&h; z &>< y lt;gt; z'
In reply to Re^2: Question for regex experts
by AnomalousMonk
in thread Question for regex experts
by evgen-i
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |