3 ms·
I vaguely remember a replacement for Python's re module, but I can't remember the name, and Googling for it is an exercise in frustration. Edit: it's "regex" -
by mark-r 10y ago
I vaguely remember a replacement for Python's re module, but I can't remember the name, and Googling for it is an exercise in frustration.
Edit: it's "regex" - https://pypi.python.org/pypi/regex https://pypi.python.org/pypi/regex. I have no idea if it behaves better with backtracking, a cursory glance at the documentation doesn't indicate any changes in that area.
- d0mine 10y agoregex module shows the same behavior as re module in this case: $ python -mtimeit -s "s=' '*20000; import regex as re" "re.search(r'\s+$', s)" # ends with spaces is fast 10000 loops, best of 3: 201 usec per loop $ python -mtimeit -s "s=' '*20000+'non-space'; import regex as re" "re.search(r'\s+$', s)" # ends with a non-space is slow 10 loops, best of 3: 3.39 sec per loop