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

前端 未结 4 782
佛祖请我去吃肉
佛祖请我去吃肉 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:29

    Difference is in escaping at least in your case. When you use / / notation, you have to escape '/' with '\/', when you're using Regexp notation you escape quotes

提交回复
热议问题