Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
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 exploiting the Monastery: (15)
As of 2014-07-23 10:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (140 votes), past polls