I want to test if a string in javascript contains normal brackets with an integer in it
var str="(12) this is a test";
var pat=/(([\d]+))/;
if (pat.test(str))
alert("true");
Works fine, but it also returns true when the string looks like this
var str="12) test";
var str="(12 test";
which should return false.
Escape brackets with \:
/\([\d]+\)/.test(str);
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