How to capture multiple groups in python with regex? [duplicate]

Solution 1:

Provided there are no nested quotes:

re.findall(r'"([^"]*)"', inputString)

Demo:

>>> import re
>>> inputString = 'According to some, dreams express "profound aspects of personality" (Foulkes 184), though others disagree.'
>>> re.findall(r'"([^"]*)"', inputString)
['profound aspects of personality']

Solution 2:

Use this one if your input can have something like this: some "text \" and text" more

s = '''According to some, dreams express "profound aspects of personality" (Foulkes 184), though others disagree.'''
lst = re.findall(r'"(.*?)(?<!\\)"', s)
print lst

Using (?<!\\) negative lookbehind it is checking there is no \ before the "