The following python code:
import re
line="http://google.com"
procLine = re.match(r'(?<=http).*', line)
if procLine.group() == "":
print(line + ": did not match regex")
else:
print(procLine.group())
does not match successfully, and outputs the following error:
Traceback (most recent call last): File "C:/Users/myUser/Documents/myScript.py", line 5, in if procLine.group() == "": AttributeError: 'NoneType' object has no attribute 'group'
When I replace the regex with just .* it works fine which suggests it's the regex that is in error, however, on https://regex101.com/ when I test my regex and string for python flavor it appears to match fine.
Any ideas?
search
instead, check documentation: "Note that patterns which start with positive lookbehind assertions will not match at the beginning of the string being searched; you will most likely want to use the search() function rather than the match() function" – Veloz