const text = "order-42-shipped"; // match returns the matches, or null when nothing matches const m: RegExpMatchArray | null = text.match(/\d+/); console.log(m ? m[0] : "no number");
match returns RegExpMatchArray | null