[issue12870] Regex object should have introspection methods

Matt Chaput report at bugs.python.org
Wed Sep 7 17:22:30 CEST 2011


Matt Chaput <matt at whoosh.ca> added the comment:

Yes, it's an optimization of my code, not the regex, as I said. Believe me, it's not premature. I've listed two general use cases for the two methods. To me it seems obvious that having to test a large number of regexes against a string, and having to test a single regex against a large number of strings, are two very common programming tasks, and they could both be speeded up quite a bit using these methods.

As of now my parsing code and other code such as PyParsing are resorting to hacks like requiring the user to manually specify the possible first chars of a regex at configuration. With the hacks, the code can be hundreds of times faster. But the hacks are error-prone and should be unnecessary. 

The PCRE library implements at least the "first char" functionality, and a lot more regex introspection that would be useful, through its pcre_fullinfo() function.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue12870>
_______________________________________


More information about the Python-bugs-list mailing list