Extract string from between quotations

Reznor picture Reznor · Jan 16, 2010 · Viewed 65.8k times · Source

I want to extract information from user-inputted text. Imagine I input the following:

SetVariables "a" "b" "c"

How would I extract information between the first set of quotations? Then the second? Then the third?

Answer

jspcal picture jspcal · Jan 16, 2010
>>> import re
>>> re.findall('"([^"]*)"', 'SetVariables "a" "b" "c" ')
['a', 'b', 'c']