const regex = /(?<type>[A-Z]{1})(?<subtype>[A-Z]{1})(?<country>[A-Z]{3})(?<last_name>[A-Z<]{25})(?<department>[A-Z0-9<]{3})(?<office>[0-9<]{3})\n(?<id_card>[A-Z0-9]{12})(?<id_check>[0-9]{1})(?<first_name>[A-Z<]{14})(?<birth_date>[0-9]{6})(?<birth_check>[0-9]{1})(?<gender>[MF]{1})(?<full_check>[0-9]{1})/g;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('(?<type>[A-Z]{1})(?<subtype>[A-Z]{1})(?<country>[A-Z]{3})(?<last_name>[A-Z<]{25})(?<department>[A-Z0-9<]{3})(?<office>[0-9<]{3})\\n(?<id_card>[A-Z0-9]{12})(?<id_check>[0-9]{1})(?<first_name>[A-Z<]{14})(?<birth_date>[0-9]{6})(?<birth_check>[0-9]{1})(?<gender>[MF]{1})(?<full_check>[0-9]{1})', 'g')
const str = `IDFRALOISEAU<<<<<<<<<<<<<<<<<<<<<<<<
970675K002774HERVE<<DJAMEL<7303216M4
IDFRAPALERMO<<<<<<<<<<<<<<<<<<061773
1309061227772BIANCA<<HELLY<8911205F7
IDFRAPETE<<<<<<<<<<<<<<<<<<<<<952042
0509952018746NICOLAS<<PAUL<8206152M3`;
// 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