下面正则表达式的含义?() 是捕获组? 出现 0 次或 1 次的内容但为什么会匹配成两个值?var re = /(hi)?/g;console.log(re.exec("hi")); // ["hi", "hi"]加? 与不加? 的区别:不加则为null:
r=/(a)/gr.exec('www') // null有?情况:
r=/(a)?/gr.exec('www') // ["", undefined, index: 0, input: "www", groups: undefined]
只有?的情况:
r=/a?/gr.exec('www') // ["", index: 0, input: "www", groups: undefined]
匹配零次
r=/,{0}/gr.exec('www') // ["", index: 0, input: "www", groups: undefined]匹配零次为什么总能成功?
添加回答
举报
0/150
提交
取消