Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Range of chars except one

by danger (Priest)
on Jan 19, 2002 at 23:08 UTC ( [id://140113]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://140113]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (6)
As of 2024-03-28 10:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found