Just looking at results from regex101, I am trying a fairly simple test:
Match /^\s+a/
(notice no g
or m
flags) against " b"
, which of course fails to match.
Just running /^\s+a/
, regex101 reports 3 steps, so very efficient.
If I do /^(?:\s)+/
or /^(?>\s)+/
, it suddenly jumps up to 24 steps. If I was to chalk this up to just having regex101 all of a sudden "count" each space whereas before it counted all the spaces as one step, then I'd expect the result to be 9 (start, 7 spaces, incorrect end character). But this is roughly triple that result. Is it still the case that its all just "what counts as a step" stuff, and they are actually equally fast (considering that non-capture groups and atomic groups should not be storing any information for later use), or is there actually a roughly 3x algorithmic slowdown just from using a useless group.
This is of course just a reduction of a problem I'm dealing with, where I am using non-capture groups for a practical reason (having two choices ored together), and seeing the number of steps explode well beyond the 2x I'd expect from checking 2 kinds of things vs. one kind of thing. I narrowed it down to this non-capture group thing.
Quick Edit: For whatever reason, regex101 will report "0 steps" in the as-you-type view, but if you click on the debugger, it will show the actual number of steps: