Mrs. Endang's letter board: your pattern is cast over the text like a net. Every matchAll match gets its number, index and groups. An interactive…
Pulling structured data out of text (logs, @user mentions, tags, key=value) needs every match and its parts. .match(/g) dropping the groups makes people write their own exec() loops, which are easy to get wrong. matchAll is clean, safe and modern.
matchAll gives every match and all its groups
TypeError when calling matchAll That is a missing g flag, made to throw on purpose so your intent (every match) is written down. Always include g..match(/g) and wondering where the groups went With g, .match returns only the full match strings. Need the groups: use matchAll (or .match without g for the first one).matchAll returns an iterator It is no array: it[0] is undefined. Spread it with [...it] or use for…of. It is also single-use: once looped, it is empty.g flag off matchAll throws a TypeError at once, though the pattern is right. Turn it back on and every match returns.\d+ Every number is caught, each with its index: handy for highlighting or replacing by position.(?<name>…) Its name shows in m.groups, and its colour on the board.\d* Empty matches show up in between: matchAll moves on one slot each time, so it never gets stuck.