reproduced here: https://jsperf.com/regexp-negation-in-group/5 Expected: * Similar performance for these two regExps * Performance for these RegExp.test should be independent of input size as they anchor to the start of the input. var noGroup = /^"[^\\"]+"/; var oneGroup = /^"(:?[^\\"])+"/; Actual: * for oneGroup regExp the performance is much worse. anywhere from x30 slower for a single line input to 5 orders of magnitude for a 10000 lines input. When running the benchmark on other browsers (chrome/firefox) The input size does not affect the performance. Thanks. Shahar.
fixed the jsperf example (was using wrong syntax for none capturing groups) http://jsperf.com/regexp-negation-in-group/6
JSPerf is down so I've added a reproducing jsfiddle instead. https://jsfiddle.net/cbepLyum/2/ (open the console to see the results).
There is still a slowdown when using groups, but it is now by a constant factor of ~4, rather than dependent on the subject length. Surprisingly, the RegExp with two non-capturing groups is 10-20% faster than the one with only one.