Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

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

by kyle (Abbot)
on Dec 11, 2007 at 05:05 UTC ( [id://656314]=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.

use Test::More; my @match_wanted = qw( abc bca cab cba bac acb ); my @match_unwanted = qw( aab abbc acc ); sub match { my $s = shift; return ( ($s =~ /(?:[abc].*){3}/) && ! ($s =~ /([abc]).*\1/) ); } plan 'tests' => ( scalar @match_wanted + scalar @match_unwanted ); ok( match( $_ ), "matches '$_'" ) for @match_wanted; ok( ! match( $_ ), "does not match '$_'" ) for @match_unwanted;
  • 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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://656314]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (8)
As of 2024-04-23 12:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found