Javascript Regexp Test Fails
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?.
Solution 1:
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?.*/;
Post a Comment for "Javascript Regexp Test Fails"