2012-12-25 23 views

回答

11

是的,patt1是一个正则表达式对象。

您可以通过patt1.source获取正则表达式源。

> console.dir(patt1); 
    /is/gi 
    global: true 
    ignoreCase: true 
    lastIndex: 0 
    multiline: false 
    source: "is" 
    __proto__: /(?:)/ 
+2

+1 - 接受这个答案仅仅是因为我先看见的 - 否则就不是他们之间没有太大差的两个:) – technojas

9

不需要正则表达式。试试这个:

> patt1.source 
"is" 
+0

+ 1 - 哇!我不知道这个方法存在于正则表达式对象上。 – technojas

0

我想你需要的是这样的:

var patt1=/[is]/gi; 
alert(patt1.test()); 
相关问题