Javascript RegExp test fails

前端 未结 1 1635
小蘑菇
小蘑菇 2020-12-21 15:12

I have problem with this regex:

(\\[|\\])[0-9]+,([0-9]+(\\[|\\])|inf\\])\\s?.*

相关标签:
1条回答
  • 2020-12-21 15:32

    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?.*/;
    
    0 讨论(0)
提交回复
热议问题