What is the difference between using “new RegExp” and using forward slash notation to create a regular expression?

前端 未结 4 769
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-06 04:46

Is there any difference between using new RegExp(\"regex\"); and /same_regex/ to test against a target string? I am asking this question because I

4条回答
  •  一整个雨季
    2020-12-06 05:50

    this will be a help for you http://www.regular-expressions.info/javascript.html see the 'How to Use The JavaScript RegExp Object' section

    if you are using RegExp(regx) regx should be in string format ex:- \w+ can be created as regx = /\w+/ or as regx = new RegExp("\\w+").

提交回复
热议问题