packing things back to regular expression

Amit Gupta emailamit at gmail.com
Wed Feb 20 13:37:14 EST 2008


Hi

I wonder if python has a function to pack things back into regexp,
that has group names.

e.g:
exp = (<?P<name1>[a-z]+)
compiledexp = re.compile(exp)

Now, I have a dictionary "mytable = {"a" : "myname"}

Is there a way in re module, or elsewhere, where I can have it match
the contents from dictionary to the re-expression (and check that it
matches the rules) and than return the substituted string?

e.g
>> re.SomeNewFunc(compilexp, mytable)
"myname"
>> mytable = {"a" : "1"}
>> re.SomeNewFunc(compileexp, mytable)
ERROR



Thanks
A



More information about the Python-list mailing list