Regular expression : non capturing groups are faster ?

candide candide at free.invalid
Tue Jan 3 09:50:45 EST 2012


Le 03/01/2012 12:56, Devin Jeanpierre a écrit :
>> The second assertion sounds more likely. It seems very odd that Python and
>> Perl implementations are divergent on this point. Any opinion ?
>
> The Python documentation oversimplifies.

You meant Perl Documentation, didn't you ?


It's a commun opinion that non-capturing groups have a price (minor), 
for instance Jan Goyvaerts, a well known regular expression guru, 
refering to Python code, tells :


non-capturing groups (...)  offer (slightly) better performance as the 
regex engine doesn't have to keep track of the text matched by 
non-capturing groups.


[link is there : 
http://stackoverflow.com/questions/2703029/why-regular-expressions-non-capturing-group-is-not-working]



It seems Javascript performs better respect to non-capturing groups : 
http://jsperf.com/regex-capture-vs-non-capture

The same for java : http://eyalsch.wordpress.com/2009/05/21/regex/
(no benchmarks).

For my part, Python tests didn't show any kind of significative penality.



More information about the Python-list mailing list