match
starts the search at the beginning of the text.
Use search
instead:
#!/usr/bin/env python import re text = 'Hello, "find.me-_/\\" please help with python regex' pattern = r'"([A-Za-z0-9_\./\\-]*)"' m = re.search(pattern, text) print m.group()
match
and search
return None
if they do not match.
I assume you get AttributeError: 'NoneType' object has no attribute 'group'
from python: this is because you assume that you will match without checking the return from re.match
.
source share