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]
LEATH
相关分类