in reply to Replace only unescaped metachars
It transforms the example string in the same way as your code. I wouldn't swear that it does for all input strings.my $escape = qr/(?<!\\)\\/; my $meta_char = qr/(?<!$escape)[?*]/; no warnings 'qw'; my %meta = qw( ? # * ? ); my $result = my $string = 't?e\\\\xt\\\\* with e\\scapes\\*'; $result =~ s/($meta_char)/$meta{ $1}/g; $result =~ s/$escape(.)/$1/gs or die; print "$string\n"; print "$result\n";
Anno
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Replace only unescaped metachars
by ikegami (Patriarch) on Feb 22, 2007 at 17:53 UTC | |
by Anno (Deacon) on Feb 22, 2007 at 18:17 UTC | |
by ikegami (Patriarch) on Feb 22, 2007 at 18:53 UTC | |
by Anno (Deacon) on Feb 22, 2007 at 19:16 UTC | |
by ikegami (Patriarch) on Feb 22, 2007 at 20:02 UTC | |
|