Regular Expressions Basics
Matching Digits
Find the first run of digits in a string.
Matching Digits
match_digits.js
const text = "item42";
const match = text.match(/\d+/);
let digits = "none";
if (match) {
digits = match[0];
}
console.log("text=" + text);
console.log("digits=" + digits);
match-digits
`match` returns details about a pattern match. Reading the first entry gives the text that matched the whole pattern.