I\'m writing a python regex that looks through a text document for quoted strings (quotes of airline pilots recorded from blackboxes). I started by trying to write a regex with
You aren't capturing anything except for the quotes, which is what Python is returning.
If you add another group, things work much better:
for quote, match in re.finditer(r'("|\')(.*?)\1', page):
print match
I prefixed your string literal with an r
to make it a raw string, which is useful when you need to use a ton of backslashes (\\1
becomes \1
).