I am trying to determine if a string matches a regular expression pattern:
expected = re.compile(r'session \d+: running')
string = "session 1234567890: running"
re.match(expected, string)
However, re.match() always returns None. Am I trying to match the decimals incorrectly? The number should be 10 digits but I would like to cover the case that it is more or less digits.
EDIT: The string parameter is actually a result of a previous match:
expected = re.compile(r'session \d+: running')
found = re.match(otherRegex, otherString)
re.match(expected, found.groups()[0])
When I print the type of found.groups()[0] it prints class str and when I print found.groups()[0], it prints the string I expect: "session 1234567890: running". Could this be why it is not working for me?
In my question I had shortened the string to the parts that were relevant. The actual string had:
The reason there were never matches is because the
'('and')'characters are special characters and I needed to escape them. The code is now:Sorry for the confusion