I think it's worth keeping in mind if just wanted a regex in JS you'd use literal notation:
const re = /ab+c/i;
And using new Regexp() is something you'd use for dynamic expressions. Could it be better, obviously, but you have to try to actually replicate the result in the post. There's plenty of worse things to worry about, even with Regular expressions, if you don't pass an argument to .test() it'll search for "undefined" so RegExp({}).test() is true and RegExp("mom").test() is false
View all comments
Show parent comment
1
u/djurze Mar 20 '24
I think it's worth keeping in mind if just wanted a regex in JS you'd use literal notation:
And using new Regexp() is something you'd use for dynamic expressions. Could it be better, obviously, but you have to try to actually replicate the result in the post. There's plenty of worse things to worry about, even with Regular expressions, if you don't pass an argument to .test() it'll search for "undefined" so RegExp({}).test() is true and RegExp("mom").test() is false