const regex = /([a-zA-Z]{3}\d{3})\s([a-zA-Z]{9}\s+\((\d{4})\)\s+\*[a-zA-Z]{3})\s+([a-zA-Z]+\d\w)\s+\.([a-zA-Z]+)\s(\d+)\s+/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('([a-zA-Z]{3}\\d{3})\\s([a-zA-Z]{9}\\s+\\((\\d{4})\\)\\s+\\*[a-zA-Z]{3})\\s+([a-zA-Z]+\\d\\w)\\s+\\.([a-zA-Z]+)\\s(\\d+)\\s+', 'gm')
const str = ` LMZ333 ALLOTMENT (0000) *TSC
HDQRM5I
.MADRIIB 160846
MADIB N4MPK/HELIB0150/1949417/HEL/IB/A/FI//RC//
HDQ5I N4MPK
1CUVILEON/CARLOS EDUARDO
1CONTRERASARNAEZ/MARIA BEGONA 1ROBLEDOCONTRERAS/PATRICIA
5I8397J/IB2198J25JUN RZGMAD CS1/0850 1220
5I8327J/IB2194J06JUL MADRZG CS1/1745 2115
OSI 5I CTCP 34606686051-M
OSI 5I POSI-DSAC//MADIB08AB/I/1
OSI 5I CARLOSCUVILIN//GMAIL.COM
= `;
// 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