Reputation: 4471
I have problem with this regex:
(\[|\])[0-9]+,([0-9]+(\[|\])|inf\])\s?.*
When I try to do code:
var rangeRegex = new RegExp("(\[|\])[0-9]+,([0-9]+(\[|\])|inf\])\s?.*");
console.log(rangeRegex.test("]1,inf] Test Expression"));
I always get false
. Why?
Upvotes: 2
Views: 1035
Reputation: 71538
When you use the RegExp
construct, you need to double escape with your backslashes:
var rangeRegex = new RegExp("(\\[|\\])[0-9]+,([0-9]+(\\[|\\])|inf\\])\\s?.*");
Or use a literal one::
var rangeRegex = /(\[|\])[0-9]+,([0-9]+(\[|\])|inf\])\s?.*/;
Upvotes: 11