Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: REgular expression to check the string that allows "a","b" and "c" to occur only once in any order.

by snoopy (Deacon)
on Dec 11, 2007 at 21:56 UTC ( #656498=note: print w/ replies, xml ) Need Help??


in reply to REgular expression to check the string that allows "a","b" and "c" to occur only once in any order.

Here's a solution based on a hash/regex combo:
my $chars = "abc"; foreach (qw/abc bca cab cba bac acb aab abbc acc/) { my %seen; my $pat = $_; $pat =~ s/([\Q$chars\E])/++$seen{$1}/gex; if ((grep {$_ == 1} values %seen) == length($chars)) { print "$_ matches\n"; } else{ print "$_ doesn't match\n"; } }
  • Comment on Re: REgular expression to check the string that allows "a","b" and "c" to occur only once in any order.
  • Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (6)
As of 2016-07-27 04:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What is your favorite alternate name for a (specific) keyboard key?


















    Results (242 votes). Check out past polls.