Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Any wisdom to how to make this work? Thanks.my $html = "<b>foo & bar</b>"; my %Map = ( '&' => '&', '"' => '"', '<' => '<', '>' => '>', "'" => ''' ); my $RE = join '|', keys %Map; # This of course encodes everything. #$html=~s!($RE)!$Map{$1}!g; # Returns <b>foo & bar</b> $html=~s/(?:(?!<\w[^>]*)($RE))/$Map{$1}/g; print $html;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: A quick regex to (imperfectly) entity encode some HTML?
by Ovid (Cardinal) on Mar 08, 2003 at 00:30 UTC | |
by Anonymous Monk on Mar 08, 2003 at 00:49 UTC | |
by Ovid (Cardinal) on Mar 08, 2003 at 01:42 UTC | |
by Anonymous Monk on Mar 08, 2003 at 06:04 UTC |