One more regular expressions question

Neil Cerutti horpner at yahoo.com
Thu Jan 18 14:50:12 CET 2007


On 2007-01-18, Victor Polukcht <vpolukcht at gmail.com> wrote:
> My pattern now is:
>
> (?P<var1>[^(]+)(?P<var2>\d+)\)\s+(?P<var3>\d+)
>
> And i expect to get:
>
> var1 = "Unassigned Number "
> var2 = "1"
> var3 = "32"
>
> I'm sure my regexp is incorrect, but can't understand where
> exactly.

Break it up using verbose notation to help yourself. Also, use
more helpful names. With names like var1 and var2 you might as
well not used named groups.

r = re.compile(r"""(?x)
    (?P<error> [^(]+ )
    (?P<errno> \d+ )
    \)
    \s+
    (?P<lineno> \d+ )""")

This way it's clearer that there's a \) with no matching \(.

-- 
Neil Cerutti
This team is one execution away from being a very good basketball team. --Doc
Rivers

-- 
Posted via a free Usenet account from http://www.teranews.com




More information about the Python-list mailing list