Why does a javascript RegExp created by /…/ work but the same created via “new RegExp” does not?

前端 未结 3 569
情歌与酒
情歌与酒 2021-01-20 05:10

I\'m confused as to what the difference here is and why one works and the other does not. Can someone explain this?

//The string to search through
var str =          


        
3条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-20 05:40

    In order to get the equivalent of /(\/\*)/g, you want new RegExp("(\\/\\*)", "g").

提交回复
热议问题