regular expressions questions

Darrell darrell at dorb.com
Mon Mar 27 18:33:47 EST 2000


"Andrew M. Kuchling"
> Derek Thomson <derek at ooc.com.au> writes:
> > I'm sure a decent syntax could be devised with a little thought. After
all, the
> > named subexpression idea is very good, and a great improvement over
Perl's
> > numbering system ie $1, $2 etc.
>
> Suggestions would be welcomed, and could rescue the idea from
> oblivion.  Feel free to post a proposed syntax; we can then refine it
> through further discussion.
>
It's a pain to dig up another tool everytime I want to match some quotes or
close tags. So I'll chance an idea, fully expecting to be wrong.

>>> s="""<a></a><a></a>"""
>>> re.search("(<(?P<aTag>a)>.*</(?P=aTag)>)",s).groups()
('<a></a><a></a>', 'a')
>>>
Create a new version of (?P=aTag) like (?Pbalance=aTag) which returns
('<a></a>, 'a')

--Darrell













More information about the Python-list mailing list