Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: regular xpression stuff

by Parham (Friar)
on Jan 20, 2002 at 21:24 UTC ( #140221=note: print w/ replies, xml ) Need Help??


in reply to regular xpression stuff

this would also work

$var = 'bat'; if ($var =~ /^[bat]{3}$/) { print "match"; } else { print "fail"; }
since you want only those letters to exist, check from beginning to end that word for each letter, the {3} should be the number of letters in that word


Comment on Re: regular xpression stuff
Download Code
Replies are listed 'Best First'.
Re: Re: regular xpression stuff
by count0 (Friar) on Jan 21, 2002 at 00:44 UTC
    If I'm understanding the question correctly, this will not work.

    It seems that the inquiring monk wants to match each letter once and only once.
    /^[bat]{3}$/ could match 'ttt', 'bba', 'aaa', etc. If that *is* undesirable, Masem's excellent reply is probably the best way to go.
      count0++ i forgot to take that into consideration

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (12)
As of 2015-07-28 09:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (254 votes), past polls