Ho to use a regular expression group reference as hash key
Andreas Martin
a.martin at perfectwww.de
Mon Mar 11 17:47:07 EST 2002
Hallo !
I'm a Python newbie and I have the following problem:
A hash person={"entry1":"value1","entry2":"value2"}
and I would like to do a substitution with regular expression (an easy
example)
like this:
pat = re.compile(r'(entry1)')
t = pat.sub(person[\1],"something...entry1...something")
I would like to substitute the "entry1" string by the respective hash
element with the group reference \1 as hash key, that is to say
t="something...value1...something".
Similar in Perl:
s/(entry1)/%person($1)/
I hope my problem is understandable.
Thanks
More information about the Python-list
mailing list