I have a question about how to match a string with regex.
The problem I have is that the string can have multiple options, like
For example: abc1b is not possible, etc.
So, the first part is always the same, but the last 2 characters can change (but as you can see, that a second character is optional).
I used Google and Python documentation, but I can't get this to work ..
What I have so far:
- Code: Select all
PATTERN = re.compile('abc[1-2] | abc3[a-b] | abc4[a-c] | abc5', re.IGNORECASE)
if PATTERN.match(TEST) :
print 'INFO Correct argument has been given: %s' % TEST
print 'INFO Incorrect argument has been given %s' % TEST
But this isn't working like I want it to be or I believe I can do it more easily..
Can someone help me a bit on this?