I am trying to match a string with a regular expression and only one of the two cases are working
String
ABCD 123 - Abcdef 0000
ABCD 123/DEFG123 - Abcdef 0000
RegEx
[A-Z]+ [A-Z0-9]{2,20} - [A-Z][a-z]+ [0-9]{4}
This matches the 1st one and Im trying to match it to both and this is the new expression I tried
[A-Z]+ [A-Z0-9\\/]{2,20} - [A-Z][a-z]+ [0-9]{4}
This matches DEFG123 - Abcdef 0000 out of the entire ABCD 123/DEFG123 - Abcdef 0000 but I am trying to get the entire string out of this. This is the code I’m using
regex = re.compile(expression)
r = regex.search(string)
The escape is what’s wrong. Taken out:
Note that my use of a raw string (
r'this is a raw string') is unnecessarily, but I obsessively use raw strings for patterns because they prevent most backslash interpolation.