http://www.perlmonks.org?node_id=140221


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

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