In the following script I would like to pull out text between the double quotes (“). However, the python interpreter is not happy and I can’t figure out why…
import re
text = 'Hello, "find.me-_/\\" please help with python regex'
pattern = r'"([A-Za-z0-9_\./\\-]*)"'
m = re.match(pattern, text)
print m.group()
The output should be find.me-/\.
matchstarts searching from the beginning of the text.Use
searchinstead:matchandsearchreturnNonewhen they fail to match.I guess you are getting
AttributeError: 'NoneType' object has no attribute 'group'from python: This is because you are assuming you will match without checking the return fromre.match.