I have three classes of characters, say letters [A-Za-z], numbers [0-9], and symbols [!@#$]. The particular symbols don't really matter for the sake of the argument. I would like to use a regular expression in Python so that I can select all permutations on these three classes with a length of three, without repetition.
For example, the following would successfully match:
a1!
4B_
*x7
And the following would fail:
ab!
BBB
*x_
a1!B
How would I go about this without explicitly writing out each potential permutation of classes in my regular expression?
I have previously attempted the following solution:
import re
regex = r"""
([A-Za-z]|[0-9]|[!@#$])
(?!\1) ([A-Za-z]|[0-9]|[!@#$])
(?![\1\2])([A-Za-z]|[0-9]|[!@#$])
"""
s = "ab1"
re.fullmatch(regex, s, re.VERBOSE)
However the string ab1 is improperly matched. This is because the group references \1 and \2 refer to the actual matched contents of the groups, and not to the regular expressions contained within the groups.
Then, how do I refer to the regular expressions contained within prior matched groups, and not to their actual contents?