in reply to Speeding up a large regex match pattern

To answer the question you asked: Yes, replacing nested capturing subgroups with non-capturing parens will improve the performance of your regexes.

In a rather crude test, almost exactly 1 order of magnitude improvement for each pair of capturing parens that you replace. That is m[((?:xxx)(?:yyy))]g runs almost exactly twice as fast as m[((xxx)(yyy))]g; and m[((?:xxx)(?:yyy)(?:zzz))]g runs almost exactly 3 times faster than m[((xxx)(yyy)(zzz))]g;; and so on.

In that test, I was assigning all the captures to an array, which obviously results in differing numbers of values in the arrays.

If you are only refering to the captures you are interested in by their aliases ($1, and ignoring $2 and $3 etc.), then the impact of using the capturing parens that you don't need is less (around 15%), but it is still significant.

The upshot is: only capture what you need, and use non-capturing parens anywhere else.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."