in reply to Range of chars except one
Two ways come to mind. First, like Juerd's, use an assertion (lookbehind in this example):
my $delete = join '','a'..'z'; # remove all lower case letters my $exclude = 'aeiou'; # exluding vowels $_ = 'Just Another Perl Hacker'; s/(?:[$delete](?<![$exclude]))+//g; print;
Or, slightly more complex, remove the exclusion characters from the deletion set first. This should prove more efficient, especially if you are repeatedly applying the deletion regex after you create it:
my $delete = join '','a'..'z'; # remove all lower case letters my $exclude = 'aeiou'; $delete =~ s/[$exclude]+//g; # excluding vowels $_ = 'Just Another Perl Hacker'; s/[$delete]+//g; print;
Either way, it is relatively simple to add or remove characters from your exclusion set.
Update: By "slightly more complex" I mean that it entails an extra step on your part --- in truth, I think it is the logically simpler version.
|
---|