Sure, you could do this with positive lookahead assertions:
^(?=.{0,5}a)(?=.{0,5}b)(?=.{0,5}c)(?=.{0,5}d)(?=.{0,5}e)(?=.{0,5}f).*
This will ensure that the letters a
through f
each appear in the first 6 characters of the string.
Or with a negative lookahead assertion:
^(?!(.).{0,4}\1|.(.).{0,3}\2|..(.).?.?\3|...(.).?\4|....(.)\5)[a-f]{6}
Yeah, I know this looks a little crazy, but basically, it will ensure that the first 6 characters are a
through f
and that the first, second, third, or fourth, or fifth character are not duplicated within the first 6 characters. You need to have so many different alternations because you don't want the lookahead condition to 'bleed' past the first 6 characters (i.e. you want to match "dfabcee"
).
Or alternatively, if your chosen platform supports it, you could use a lookbehind:
^(([a-f])(?<!\2.*\2)){6}
This will ensure that the first 6 characters are a
through f
and that they do not appear after instance of the same character.