Check if a string contains brackets with an integer in it
I want to check if a string in javascript contains regular 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 also returns true when the string looks like this:
var str="12) test";
var str="(12 test";
which should return false.
+3
Chris
source
to share
1 answer
Sliding brackets with \
:
/\([\d]+\)/.test(str);
+8
dmk
source
to share