const regex = /^\D*(\d)\D*(\d)\D*$/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('^\\D*(\\d)\\D*(\\d)\\D*$', 'gm')
const str = `Z189
I142
M395
L210
V467
M203
Q277
Q461
Y440
S250
M162
Q96
22Q
W148
Q72
T22T
22TWE22
12E34`;
// Reset `lastIndex` if this regex is defined globally
// regex.lastIndex = 0;
let m;
while ((m = regex.exec(str)) !== null) {
// This is necessary to avoid infinite loops with zero-width matches
if (m.index === regex.lastIndex) {
regex.lastIndex++;
}
// The result can be accessed through the `m`-variable.
m.forEach((match, groupIndex) => {
console.log(`Found match, group ${groupIndex}: ${match}`);
});
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for JavaScript, please visit: https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions