Regex question! Is there a performance benefit to marking groups as non-capturing in regex.test(string) calls? For example, to see if a string starts with one of several values:
/^(doggo|cat)/.test(petName)
vs
/^(?:doggo|cat)/.test(petName)
cc @mathias
-
-
As
@mathias says, creating the result object will be a tad cheaper (fewer substring calls, fewer allocations). The generated irregexp code will be a tad simpler (perf impact might not be noticeable but this'd affect all RegExp operations).Thanks. Twitter will use this to make your timeline better. UndoUndo
-
-
-
yes. you would definitely perform less work.
Thanks. Twitter will use this to make your timeline better. UndoUndo
-
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.
JavaScript, HTML, CSS, HTTP, performance, security, Bash, Unicode, i18n, macOS.