下面正則表達式的含義?() 是捕獲組? 出現(xiàn) 0 次或 1 次的內(nèi)容但為什么會匹配成兩個值?var re = /(hi)?/g;console.log(re.exec("hi")); // ["hi", "hi"]加? 與不加? 的區(qū)別:不加則為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]匹配零次為什么總能成功?
正則表達式 /(hi)?/g 的含義?
慕蓋茨4494581
2019-01-29 21:13:12