overlapping find and replace

Michael Lush mjlush at ebi.ac.uk
Mon Oct 18 16:11:45 BST 2010



I have a string ABCDEFGH and want to highlight two overlapping hits
BCDE and DEFG in HTML to make A<b>BC<i>DE</b>FG</i>H

The obvious $string =~ s{(BCDE|DEFG)}{<b>$1</b>}g; does not work as the 
modified string doesn't match the second query and I don't get differnet
fonts for each overlapping match.

Is there a conventional way of doing this?

--
Michael


More information about the london.pm mailing list