what is the meaning of the following regular expression?
() is the capture group
? Content that appears 0 or 1 times
but why do they match to two values?
var re = /(hi)?/g;
console.log(re.exec("hi")); // ["hi", "hi"]
add? Are you in or out? The difference:
null:
r=/(a)/g
r.exec("www") // null
?:
r=/(a)?/g
r.exec("www") // ["", undefined, index: 0, input: "www", groups: undefined]
?:
r=/a?/g
r.exec("www") // ["", index: 0, input: "www", groups: undefined]
r=/,{0}/g
r.exec("www") // ["", index: 0, input: "www", groups: undefined]
Why is it always successful to match zero times?