Is it possible to write a regular expression which will match any subset of a given set of characters
a1 ... an
?
I.e. it should match any string whe
Can't think how to do it with a single regex, but this is one way to do it with n
regexes: (I will usr 1
2
... m
n
etc for your a
s)
^[23..n]*1?[23..n]*$
^[13..n]*2?[13..n]*$
...
^[12..m]*n?[12..m]*$
If all the above match, your string is a strict subset of 12..mn
.
How this works: each line requires the string to consist exactly of:
a particular one
a particular one
a particular one
If this passes when every element in turn is considered as a particular one
, we know:
as required.
for completeness I should say that I would only do this if I was under orders to "use regex"; if not, I'd track which allowed elements have been seen, and iterate over the characters of the string doing the obvious thing.