JavaScript and regular expressions: literal syntax Vs. RegExp object

前端 未结 2 1268
野趣味
野趣味 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:50

    You need to double escape \ characters in string literals, which is why the regex literal is typically preferred.

    Try:

    'Z[\\s\\S]*?Z'
    

提交回复
热议问题