4 ms·
Javascript has regex literals /foo\sbar/i; Is the same as: new RegExp('foo\\sbar', 'i');
by Ardren 9y ago
Javascript has regex literals
/foo\sbar/i;
Is the same as:
new RegExp('foo\\sbar', 'i');
- hoytech 9y agoOne thing that annoys me a bit about the JS syntax though: As far as I know, JS regexp literals don't have custom delimiter support. For instance in perl you can do this: $str =~ m{/some/path/\w+} But in JS you need to escape the / characters, or use a normal string as an argument to Regexp, in which case you need to escape the backslashes: /\/some\/path\/\w+/ Regexp("/some/path/\\w+")