5

Is it possible to compile regex rules in Node.js for faster usage?

1
  • You mean something different than var pattern = /regex/;? Commented May 26, 2012 at 12:28

2 Answers 2

8

V8 compiles regexes automatically. See http://www.scribd.com/doc/16921039/V8-Internals-Building-a-High-Performance-JavaScript-Engine

Sign up to request clarification or add additional context in comments.

1 Comment

Oh, nice! I'm used to Python and am relatively new to Node.js. Wasn't aware V8 does it automatically. Thanks!
3

Node.js is just JavaScript running on V8 so you really only have what V8 provides, namely:

var r = new RegExp("abc", 'i');

V8 will do it's own optimization, probably even on inline regexes.

1 Comment

If you are using regex literal such as /abc/i, the new RegExp is redundant

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.