Python RegExp

D H no at spam
Wed Mar 23 01:12:34 CET 2005


davidchipping at gmail.com wrote:
> I have a string which I wish to match using RE, however when I run my
> comparison (using the match method) on my machine it never returns,
> using the CPU fully.

In your case it may be simpler to just split the string into groups. 
You don't even need regular expressions or a parser.

buff = r"#1 1 550 111 SYNC_PEER RES <YP>syncpeers=(id=54325432;add=10." \
"0.0.1;port=89;up=89),(id=97899;add=10.0.0.1;port=543;up=543)," \
             "(id=54325432;add=10.0.0.1;port=89;up=8)"

tran, sess, ndto, ndf, cmd, dirr, rest = buff.split()

eq = rest.find("=")
parmname = rest[0:eq]
parms = rest[eq+1:].split(",")

for parm in parms:
	parmitems = parm[1:-1].split(";")
	for item in parmitems:
		name, val = item.split("=")
		print name, val
	print "---"



More information about the Python-list mailing list