LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 12-11-2007, 06:47 AM   #1
sylvaticus
Member
 
Registered: Apr 2006
Posts: 49

Rep: Reputation: 15
Question [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
should retrieve me
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])
Hovewer I got
Code:
"AA","BB","CC")*1.12345*BVAR("DD","CC","EE"
How can I tell the regExp to get the more "internal" match ???
 
Old 12-11-2007, 07:00 AM   #2
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 241Reputation: 241Reputation: 241
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"""
while 1:
    try:
        ind = s.index('"')
        s=s[ind+1:]
        end = s.index('"')
        print s[:end]
        s=s[end+1:]
    except: break
output:
Code:
# ./test.py
AA
BB
CC
DD
CC
EE
however, if you are bent on using regexp

Code:
import re
pat = re.compile('"(.*?)"')
s="""MYVAR("AA","BB","CC")*1.12345*BVAR("DD","CC","EE") * 2"""
print pat.findall(s)
output:
Code:
# ./test.py
['AA', 'BB', 'CC', 'DD', 'CC', 'EE']
 
Old 12-11-2007, 07:28 AM   #3
sylvaticus
Member
 
Registered: Apr 2006
Posts: 49

Original Poster
Rep: Reputation: 15
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
 
  


Reply

Tags
expressions, mark, python, quotation, regular


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Execvp With Quotation Marks amitbern Programming 10 11-25-2005 11:28 AM
no quotation marks jdoe9898 Linux - Newbie 1 10-12-2005 04:07 AM
Quotation Marks Linux / Firefox jjdoll42 Linux - Software 6 04-19-2005 11:13 AM
Quotation marks and strings - in C lazyuser Programming 5 01-25-2005 09:14 AM
quotation marks donīt display in X Obi-Wan_Kenobi Slackware 1 08-31-2003 11:42 AM


All times are GMT -5. The time now is 06:07 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration