Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

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

by BrowserUk (Patriarch)
on Dec 11, 2007 at 05:09 UTC ( [id://656315]=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.

m/ (?=^[^a]*a[^a]*$) ## One a and no other a's (?=^[^b]*b[^b]*$) ## One b and no other b's (?=^[^c]*c[^c]*$) ## One c and no other c's ^.{3}$ ## Exactly three chars /x and print "$_: matched" for 'aaa'..'ccc';; abc: matched acb: matched bac: matched bca: matched cab: matched cba: matched

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
  • 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 bart (Canon) on Dec 11, 2007 at 13:25 UTC
    This looks like overkill.

    If a string is required to contain all of an "a", a "b" and a "c" and its length is limited to 3, then it can only contain one of each.

    So this ought to suffice:

    /^(?=.*a)(?=.*b)(?=.*c).{3}\z/

    Of course, yours is the way to go if the length is not limited to 3.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://656315]
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: (None)
    As of 2024-04-25 01:07 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found