Regexp optimization question

Magnus Lie Hetland mlh at furu.idi.ntnu.no
Fri Apr 23 11:59:54 EDT 2004


In article <mailman.950.1082710898.20120.python-list at python.org>,
Fredrik Lundh wrote:
>Magnus Lie Hetland wrote:
>> but now I have to find out which one of them matched at a
>> certain location.
>
>the techniques discussed in this article may be helpful:
>
>    http://effbot.org/zone/xml-scanner.htm

Yes, this is indeed useful. The most useful thing, I guess, is the
lastindex attribute (which was pointed out earlier) -- but I suspect I
can't use it, as I have to know all the patterns that were matched at
a given location (and let the parser choose which one to use, based
on its context-dependent priorities). Or, at least, that's how it
seems to me now.

I *could*, of course, say that ambiguity is not allowed -- or that the
effects aren't defined. Or maybe I could order the patterns in terms
of specificity (but analyzing regexps for specificity is no mean feat,
of course ;)

Thanks for the pointer, though -- a nice tutorial!

></F>

-- 
Magnus Lie Hetland              "Wake up!"  - Rage Against The Machine
http://hetland.org              "Shut up!"  - Linkin Park



More information about the Python-list mailing list