Closed zackbloom closed 11 years ago
It doesn't matter on modern browsers (they cache regular expressions), but on older ones, it can be more performant to define regex outside of the function where they're used, so they don't have to be recompiled on every keystroke.
Can you provide a live example on something like jsperf.com? I'd like to see the actual savings first.
Edit: Tested it myself, didn't really improve performance. In IE7, things even got worse.
It doesn't matter on modern browsers (they cache regular expressions), but on older ones, it can be more performant to define regex outside of the function where they're used, so they don't have to be recompiled on every keystroke.