I'm using regex library 're' in Python (2.7) to validate a flight number.
I've had no issues with expected outputs using a really helpful online editor here: http://regexr.com/
My results on regexr.com are: https://i.sstatic.net/YC7ra.jpg
My code is:
import re
test1 = 'ba116'
###Referencelink: http://academe.co.uk/2014/01/validating-flight-codes/
p = re.compile('/^([a-z][a-z]|[a-z][0-9]|[0-9][a-z])[a-z]?[0-9]{1,4}[a-z]?$/g')
m = p.search(test1) # p.match() to find from start of string only
if m:
print 'It works!: ', m.group() # group(1...n) for capture groups
else:
print 'Did not work'
I'm unsure why I get the 'didn't work' output where regexr shows one match (as expected)
I made a much simpler regex lookup, and it seemed that the results were correct, so it seems either my regex string is invalid, or I'm using re.complile (or perhaps the if loop) incorrectly?
'ba116' is valid, and should match.
/you don't need them in python. Thats probably why its not working