Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

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

by AK108 (Friar)
on Dec 12, 2007 at 13:11 UTC ( [id://656615]=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.

This isn't a regex, but I don't think anyone mentioned it.
my @letters = qw(abc cba cab bab blab); for (@letters) { if(join('', sort split //, $_) eq "abc") {print "$_ matched\n"} else {print "$_ didn't match\n"} }
(My initial thought was to add up the ord() values of the characters. That would work too, but wouldn't be as concise since there isn't a reduce operator in Perl 5.)
  • Comment on Re: REgular expression to check the string that allows "a","b" and "c" to occur only once in any order.
  • Download Code

Replies are listed 'Best First'.
Re^2: REgular expression to check the string that allows "a","b" and "c" to occur only once in any order.
by parv (Parson) on Dec 12, 2007 at 20:42 UTC

    That is simple!

    A problem might arise if the desired letters could be part of a bigger string. Lacking any comments by isha on the specification :( so far, your solution is just as good.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2024-04-23 20:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found