Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Andrzejek on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help with a python regexp

Status
Not open for further replies.

ffeignol

ISP
Apr 22, 2005
1
US
Hello,

I need to work with a python API I've been provided but I'm not that familar with python. I need a python regexp that will extract the "key", "value" and "comment" from this line of php:

define('DB_PASSWORD', 'password'); // ...and password

DB_PASSWORD is the key, password is the value and the // ... is the comment.

TIA
 
something like this?
Code:
>>> import re
>>> s = "define('DB_PASSWORD', 'password'); // ...and password"
>>> r = "define\('([^']*)', '([^']*)'\); (// .*)"
>>> m = re.match( r, s )
>>> print "key:\t%s\npass:\t%s\ncomm:\t%s" % ( m.group(1), m.group(2), m.group(3) )
key:    DB_PASSWORD
pass:   password
comm:   // ...and password
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top