I recently came across this example from MDN showcasing the use of the string's match method:
var str = "For more information, see Chapter 3.4.5.1";
var re = /(chapter \d+(\.\d)*)/i;
var found = str.match(re);
console.log(found);
// logs ["Chapter 3.4.5.1", "Chapter 3.4.5.1", ".1"]
// The first match is "Chapter 3.4.5.1" and it corresponds to (Chapter \d+(\.\d)*).
// The value ".1" is captured from (\.\d)
I find the results of the RegExp matching in JavaScript a bit confusing. I expected it to return ["Chapter 3.4.5.1", ".4.5.1"]. Can someone clarify why the result is different?