Question about regular expression

massi_srb at massi_srb at
Wed Sep 30 20:34:04 CEST 2015

Hi everyone,

firstly the description of my problem. I have a string in the following form:

s = "name1 name2(1) name3 name4 (1, 4) name5(2) ..."

that is a string made up of groups in the form 'name' (letters only) plus possibly a tuple containing 1 or 2 integer values. Blanks can be placed between names and tuples or not, but they surely are placed beween two groups. I would like to process this string in order to get a dictionary like this:

d = {
    "name1":(0, 0),
    "name2":(1, 0),
    "name3":(0, 0),
    "name4":(1, 4),
    "name5":(2, 0),

I guess this problem can be tackled with regular expressions, but I have no idea bout how to use them in this case (I'm not a regexp guy). Can anyone give me a hint? any possible different approach is absolutely welcome.

Thanks in advance!

More information about the Python-list mailing list