python regex for repeating string

Posted by Lars Nordin on Stack Overflow See other posts from Stack Overflow or by Lars Nordin
Published on 2011-01-10T21:47:00Z Indexed on 2011/01/10 21:53 UTC
Read the original article Hit count: 227

Filed under:
|
|

I am wanting to verify and then parse this string (in quotes):

string = "start: c12354, c3456, 34526;"
//Note that some codes begin with 'c'

I would like to verify that the string starts with 'start:' and ends with ';' Afterward, I would like to have a regex parse out the strings. I tried the following python re code:

regx = r"V1 OIDs: (c?[0-9]+,?)+;" 
reg = re.compile(regx)
matched = reg.search(string)
print ' matched.groups()', matched.groups()

I have tried different variations but I can either get the first or the last code but not a list of all three.

Or should I abandon using a regex?

© Stack Overflow or respective owner

Related posts about python

Related posts about regex