JavaScript and regular expressions: literal syntax Vs. RegExp object

前端 未结 2 1266
野趣味
野趣味 2021-02-07 05:16

I have some troubles with this small JavaScript code:

var text=\"Z Test Yeah ! Z\";

// With literal syntax, it returns tr         


        
2条回答
  •  清酒与你
    2021-02-07 05:55

    I think it's because you have to escape your backslashes, even when using single quotes. Try this:

    new RegExp('Z[\\s\\S]*?Z','g')
    

提交回复
热议问题