var str = "1405199610";
var re = new RegExp("\d{10}");
var myArray = re.test(str);
myArray gives false!
How is this possible? I tested this with online regex checkers and it checks out ok. When i try it in the console or jsfiddler, it doesn't work. Am I missing something?
var re = new RegExp("\\d{10}");
you need to escape the \
when regexp is created by RegExp()
object
See MDN reference
...Also do not forget to escape \ itself while using the new RegExp("pattern") notation since \ is also an escape character in strings.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With