我有以下正则表达式模式和字符串:
var str="Is this all there is?";
var patt1=/is/gi;
Run Code Online (Sandbox Code Playgroud)
我想提取主表达式is(没有修饰符)来var patt1使用另一个正则表达式,我们可以var patt2为了参数而调用它.
如何在vanilla JavaScript中做到这一点?
xda*_*azz 11
是的,patt1是一个正则表达式对象.
你可以得到正则表达式的源代码patt1.source.
> console.dir(patt1);
/is/gi
global: true
ignoreCase: true
lastIndex: 0
multiline: false
source: "is"
__proto__: /(?:)/
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
130 次 |
| 最近记录: |