http://qs321.pair.com?node_id=326871

ChrisR has asked for the wisdom of the Perl Monks concerning the following question:

I have been struggling with a simple (or so I thought) regex for a day now and have only succeeded in confusing myself. Here's the scenario:
A user supplied string may contain 1 or more of the characters smtwhfa in any order. That's as easy as
$string =~ /^[smtwhfa]*$/
But this allows for duplicate characters and I need to be sure that no character is in the string more than once. For example:
swma is OK
smsa is NOT OK

I tried many variations of what I thought could work but to no avail. So, of course man perlre was my next stop. Then searches on Perl Monks and Google and then the camel book. The one thing that seemed to be the answer was a negative lookahead assertion but I don't really understand it. I'm not even sure if this the road I need to take.
Here is some of what I tried:
$string =~ /^[smtwhfa]*(?![smtwhfa])$/ $string =~ /^[s{1}m{1}t{1}w{1}h{1}f{1}a{1}]*$/ $string =~ /^([smtwhfa])(?!\1)*$/
And numerous other more embarrassing attempts.

I know there are other ways of doing this like this very ugly and inefficient example:
my $string = "smasm"; my @array = split(//, $string); my %hash; foreach(@array) { $hash{$_} ++; } foreach(keys %hash) { if($hash{$_} > 1) { print "ERROR\n"; last; } }
But I would really like to do this with a single regex so that it easily portable to other languages.

Any hints or examples that might lead me in the right direction will be greatly appreciated.