Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Hello monks,
I am doing some substitutions of strings with a regex. For example, I have code like this:
But now the problem is that some of the words have embedded XML tags. I would like to still perform the substition but keep the XML tag. There is at most one XML tag in a word; for example: <tag>f</tag>oo should become <tag>b</tag>ar%dictionary = (foo => 'bar', baz => 'w00t'); $str =~ s[$_][$dictionary{$_}] for keys %dictionary;
and
<b>fo</b>o should become <b>ba</b>rIs there a simple way of doing this without writing out all of the possible combinations? Thanks!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Keeping tags in regex
by choroba (Cardinal) on May 17, 2012 at 15:56 UTC | |
by Anonymous Monk on May 17, 2012 at 17:05 UTC | |
|
Re: Keeping tags in regex
by choroba (Cardinal) on May 17, 2012 at 22:51 UTC | |
|
Re: Keeping tags in regex
by afoken (Chancellor) on May 17, 2012 at 16:25 UTC | |
by Anonymous Monk on May 17, 2012 at 17:16 UTC |