const regex = new RegExp('U\\d*_([A-Za-z0-9\\_]+)(?:\\s*\\d\\s*\\d*\\s*\\d*\\s*\\d*\\s*\\d*\\s*\\d*\\s*\\d*\\s*(\\d*)\\s*\\d*\\s*\\d*\\s*\\d*\\s*(\\d*)\\s*\\d*\\s*\\d*\\s*(\\d*))', 'gm')
const str = `U2_BOMBEROS_MERIDA4 1 734 4 0 0 0 0 54524 1 1 1 55302 0 0 54524 0 1 1 0 0 OFF 12 412 43 0 OFF OFF 0 0 1 1 1 10 10 10 10 0 0 OFF 3 0 0 0 OFF 90 180 0 OFF 0 0 0 OFF OFF OFF 90 180 0 OFF 0 0 OFF OFF OFF OFF OFF OFF ON 0 0 0 0 OFF OFF OFF OFF OFF OFF OFF OFF OFF OFF OFF OFF OFF 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 OFF 0 OFF OFF
U2_SAN_JAVIER_DEL_VALLE5 1 734 4 0 0 0 0 53955 1 1 1 55303 0 0 53955 0 1 1 0 0 OFF 12 412 43 0 OFF OFF 0 0 1 1 1 10 10 10 10 0 0 OFF 3 0 0 0 OFF 90 180 0 OFF 0 0 0 OFF OFF OFF 90 180 0 OFF 0 0 OFF OFF OFF OFF OFF OFF ON 0 0 0 0 OFF OFF OFF OFF OFF OFF OFF OFF OFF OFF OFF OFF OFF 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 OFF 0 OFF OFF
`;
// 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