I need to parse this string, with only one regular expression in Python. For every group I need to save the value in a specific field. The problem is that one or more of the parameters may be missing or be in a different order. (i.e. domain 66666 ip nonce, with the middle part missing)
3249dsf 2013-02-10T06:44:30.666821+00:00 domain constant 66666 sync:[127.0.0.1] Request: pubvalue=kjiduensofksidoposiw&change=09872534&value2=jdmcnhj&counter=232&value3=2&nonce=7896089hujoiuhiuh098h
I need to assign:
time=2013-02-10T06:45:30.666821+00:00(constant format)domain=domain(string)code=66666(integer)ip=127.0.0.1(string)pubvalue=kjiduensofksidoposiw(string of fixed length)nonce=7896089hujoiuhiuh098h(string)
EDIT
This is an example on how the string can vary: 123dsf 2014-01-11T06:49:30.666821+00:00 google constant 12356 sync:[192.168.0.1] Request: pubvalue=fggggggeesidoposiw&nonce=7896089hujoiuhiuh098h
Thank you in advance for showing me the way.
re.matchon the entire pattern for each term. Probably it would be better have intermediate steps, like: split the string on whitespace, split the request on&, then check the terms for the things you want. If you can define exactly what will change and what won't, that will help you make the most efficient algorithm. For example, if the time is always the second term, you can just take this instead of testing it.