var regEx = new RegExp("/[0-9]/");
var test = 'TREE'
alert(test.match(regEx));
or
var regEx = new RegExp("/[0-9]/");
var test = '1234'
alert(test.match(regEx));
Why do they return null?
Am i missing something here?
(Ok, the debate mentally drained me last night)
When you are using new RegExp, you don't need the delimiters (/).
var regEx = new RegExp("[0-9]");
var test = '1234'
alert(test.match(regEx));
You only need the slashes if you are using a regex literal (which I prefer using to new RegExp).
var regEx = /[0-9]/;
var test = '1234'
alert(test.match(regEx));
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