regular expression questions
Darrell
darrell at dorb.com
Thu Mar 30 21:38:12 EST 2000
"Andrew M. Kuchling"
>
> Note that you can already do something like this by using a non-greedy
> .*? instead of .*, and then using the findall() method:
>
Yes I know. Should have used a nested example.
> import re
>
> p = re.compile("(<(?P<aTag>a)>(.*?)</(?P=aTag)>)")
>
> s="""<a></a><a></a><b> foo </b>"""
> m = p.match(s)
> print m and m.__dict__
> print p.findall(s)
>
> The .findall() returns [('<a></a>', 'a', ''), ('<a></a>', 'a', '')].
> But how would you want to receive the data where there's potential
> recursion, as where the input is <a>data <a>data</a> more data</a>?
>
s=""<a>data <a>data</a> more data</a>"""
['<a>data <a>data</a> more data</a>', ' <a>data</a>']
This seems natural to me.
--Darrell
More information about the Python-list
mailing list