simple parsing help

EP EP at zomething.com
Sat Jul 24 14:50:18 EDT 2004


Steve wrote:

> I have a string that looks kinda like "Winner (121,10) blah blah blah 
> Winner (10,400) blah blah Winner (103,4) blah blah..."
> 
> I just want to extract the coordinate parts of the string (xxx,xxx)
> which could be 1-3 characters and put them into an array ideally. 
> What is the easiest way to do this in Python?  Can anyone provide a
> simple line or two of code to help me get started?


Maybe this will get you going:

>>> thisStr="""Winner (121,10) blah blah blah Winner (10,400) blah blah Winner (103,4) blah blah..."""
>>> import re
>>> getCoords=re.compile("([(])([0-9]{1,3})([,])([0-9]{1,3})([)])")
>>> for hit in getCoords.finditer(thisStr):
	print hit.group(2),'\t',hit.group(4)

	
121 	10
10 	400
103 	4


cheers....



Eric Pederson
http://www.songzilla.blogspot.com
:::::::::::::::::::::::::::::::::::
domainNot="@something.com"
domainIs=domainNot.replace("s","z")
ePrefix="".join([chr(ord(x)+1) for x in "do"])
mailMeAt=ePrefix+domainIs
:::::::::::::::::::::::::::::::::::



More information about the Python-list mailing list