3 ms·
Perl, Ruby and some other languages support a similar 'extended' RegEx syntax which allows comments and disregards whitespace (in Ruby, you use the 'x' flag on
by gmac 15y ago
Perl, Ruby and some other languages support a similar 'extended' RegEx syntax which allows comments and disregards whitespace (in Ruby, you use the 'x' flag on a Regexp literal).
For those using plain JavaScript -- or wanting to do a one-off conversion -- I wrote a simple JS function that converts an extended RegEx to a plain one:
http://blog.mackerron.com/2010/08/08/extended-multi-line-js-regexps/ http://blog.mackerron.com/2010/08/08/extended-multi-line-js-...
- elijahmanor 15y agoYeah, my guess is that CoffeeScript took direction from those languages for this feature. Nice function to convert annotated string to a regex. I wonder if this is being considered in the next versions of JavaScript? Or better yet... native annotation? I like the CoffeeScript approach since that logic is done at compile time and not when it is being executed.