in reply to Regex (lookahead) Confusion
...may contain 1 or more of the characters smtwhfa in any order.
That means you want '+' instead of '*' for the quantifier.
You can make sure there are no repetitions with a hash over the characters:
That uses the uniqueness of hash keys to enforce your requirement.if ( $string =~ /^[smtwhfa]+$/ and length $string == do { my %hsh; @hsh{split //, $string} = (); keys %hsh; } ) { # everything's ok }
You can do that with regex lookahead by a negated match, $string !~ /([smtwhfa])(?=.*\1)/ after the match for the character class. That returns true if there is no match for a repeated character (untested).
After Compline,
Zaxo
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Regex (lookahead) Confusion
by ChrisR (Hermit) on Feb 06, 2004 at 13:24 UTC |