[regExp] Retrieve content embedded in quotation marks
Hello.. I need to retrieve a list of variables from a line of a programming language where variables are enclosed in quotation marks..
Eg. Code:
MYVAR("AA","BB","CC")*1.12345*BVAR("DD","CC","EE") * 2 AA BB CC DD CC EE I am using python and up to now I arrived to write the following regexp: Code:
variables = re.findall("\".+\"", myLine[i]) Code:
"AA","BB","CC")*1.12345*BVAR("DD","CC","EE" |
there's no need to use regexp, you can make use of Python's basic string manipulation methods
eg ( tested only on that string) Code:
s="""MYVAR("AA","BB","CC")*1.12345*BVAR("DD","CC","EE") * 2""" Code:
# ./test.py Code:
import re Code:
# ./test.py |
Thank you very much. I was going in the direction of your fist example (using "split()" as I am a python-newby) before reading your text.
Following your text I learned that *? make the * operator to works in "minimal fashion" (from http://docs.python.org/lib/re-syntax.html ) that was my problem. I suppose also that the quotation marks are not in the output because they are outside the () operator... Thank you very much... Antonello |
All times are GMT -5. The time now is 08:56 PM. |