I have problem with this regex:
(\[|\])[0-9]+,([0-9]+(\[|\])|inf\])\s?.*

Debuggex Demo
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?
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?.*/;
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