The match for 1 is incorrect, you can't use a character class like that. Try this test
#!perl use strict; use YAPE::Regex::Explain; my $str = '> milk & honey < < bill&ben >'; sub convert { my $input_stream = shift; return undef unless $input_stream; my %char_swap_hash = ( 1 => {OLD => '&[^(amp;)|(lt;)|(gt;)]', NEW => '&'}, # don't mat +ch legit '&' codes 2 => {OLD => '<', NEW => '<'}, 3 => {OLD => '>', NEW => '>'} ); $input_stream =~ s/$char_swap_hash{$_}{OLD}/$char_swap_hash{$_}{NEW} +/g for keys %char_swap_hash; return $input_stream; } print YAPE::Regex::Explain->new('&[^(amp;)|(lt;)|(gt;)]')->explain; print convert($str),"\n";
Alternative
pojmy %htm = ( '&' => '&', '>' => '>', '<' => '<', ); my $REx = qr'(&(?!(?:amp|lt|gt);)|[><])'; $str =~ s/$REx/$htm{$1}/g; print $str."\n\n"; print YAPE::Regex::Explain->new($REx)->explain;
In reply to Re^5: Interpolating subroutine call in SQL INSERT INTO SELECT statement
by poj
in thread Interpolating subroutine call in SQL INSERT INTO SELECT statement
by shadowsong
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |