Specific work -
This should result in an alignment that consists of only 4 different char of string> = 4 in length.
# ^(?=.*(.).*(?!\1)(.).*(?!\1|\2)(.).*(?!\1|\2|\3)(.))(?:\1|\2|\3|\4)+$ ^ (?= .* ( . ) .* (?! \1 ) ( . ) .* (?! \1 | \2 ) ( . ) .* (?! \1 | \2 | \3 ) ( . ) ) (?: \1 | \2 | \3 | \4 )+ $
Perl Test:
if ("upepipipeu" =~ /^(?=.*(.).*(?!\1)(.).*(?!\1|\2)(.).*(?!\1|\2|\3)(.))(?:\1|\2|\3|\4)+$/) { print "unique chars: '$1' '$2' '$3' '$4'\n"; print "matched: '$&'\n"; }
Exit →
unique chars: 'i' 'p' 'e' 'u' matched: 'upepipipeu'
Test code for @aliteralmind:
@Ary = ("aabbccdd", "dictionary", "reassess", "aaaa"); for( @Ary ) { if ("$_" =~ /^(?=.*(.).*(?!\1)(.).*(?!\1|\2)(.).*(?!\1|\2|\3)(.))(?:\1|\2|\3|\4)+$/) { print "unique chars: '$1' '$2' '$3' '$4'\n"; print "matched: '$&'\n\n"; } else { print "Failed-> '$_'\n\n"; } }
Exit →
unique chars: 'a' 'b' 'c' 'd' matched: 'aabbccdd' Failed-> 'dictionary' unique chars: 'r' 'a' 'e' 's' matched: 'reassess' Failed-> 'aaaa'
source share