What do the common regular expression methods do?
There are four regular expression methods that are worth knowing, and they differ in what they give back to you. The test() method gives you true or false, so it only answers the question "does this pattern appear anywhere?". The match() method gives you an array of the matches, or the first match together with its capture groups when the pattern does not have the global flag. The matchAll() method gives you an iterator that walks through every match, and it is the modern way to replace the old global match() behaviour. The replace() and replaceAll() methods swap the matched text for something else.
const text = 'order-1234, order-5678';
console.log(text.match(/\d+/g)); // ["1234", "5678"]
console.log(text.match(/\d{4}/)); // ["1234", "5678"] - first match only
console.log(text.replace(/\d+/g, '#')); // "order-####, order-####"
console.log(text.split(/,\s*/)); // ["order-1234", "order-5678"]
console.log(/^order/.test(text)); // true
console.log(/\d{5}/.test(text)); // false
The difference between match() with the global flag and without it catches people out. Without the flag, the array starts with the whole match, and the rest of the items are the capture groups. With the flag, the array holds only the full matches and there is no group information at all. When you want the groups from every single match, use matchAll(), because it always gives you the full match and the groups together for each one.
The split() method is also more useful with a pattern than people expect. Splitting on a pattern that matches any run of whitespace is a better way to normalise a sentence than splitting on a single space, because it also handles tabs and repeated spaces without producing empty strings in the middle.
One last thing about replace(). With a plain string pattern it replaces only the first match, and with a regular expression it also replaces only the first match unless you add the global flag. The replaceAll() method always replaces everything, and it accepts a regular expression too, in which case you do not need the global flag.