in reply to Hazardous characters filter
Perhaps the following, which uses a negative lookhead and a negative lookbehind, will be helpful:
use strict; use warnings; my $test = "this is not OK < but this is ok <url>"; print rep($test); sub rep { $_[0] or return $_[0]; $_[0] =~ s/<(?!url)|(?<!url)>//g; return $_[0]; }
Output:
this is not OK but this is ok <url>
Your sub returns '' if $_[0] evaluates to false. This means that 0 and !defined $_[0] would convert to '', and perhaps that's your intent. In these cases, the above just returns what was sent (if anything), so you may need to adjust it.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Hazardous characters filter
by no_slogan (Deacon) on Mar 25, 2014 at 14:59 UTC |
In Section
Seekers of Perl Wisdom