const regex = /(?<type>[A-Za-z]{1})(?<subtype>[A-Za-z<]{1})(?<expcountry>[A-Za-z]{3})(?<docnumber>[0-9A-Za-z<]{9})(?<docnumbercheck>[0-9]{1})(?<complement>[0-9a-zA-Z<]{15})\n(?<birthdate>[0-9]{6})(?<birthcheck>[0-9]{1})(?<sex>[mfMF]{1})(?<expiredate>[0-9]{6})(?<expirecheck>[0-9]{1})(?<nacionality>[A-Za-z]{3})(?<optional>[a-zA-Z0-9<]{11})(?<linecheck>[0-9]{1})\n(?<lname>[A-Z]+)(?<lname2><[A-Z]+){0,}<<(?<spacing>[<]{0,})(?<fname>[A-Z]+)(?<mname1><[A-Z]+){0,}(?<namecomplement>[a-zA-Z<]+){0,}/;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('(?<type>[A-Za-z]{1})(?<subtype>[A-Za-z<]{1})(?<expcountry>[A-Za-z]{3})(?<docnumber>[0-9A-Za-z<]{9})(?<docnumbercheck>[0-9]{1})(?<complement>[0-9a-zA-Z<]{15})\\n(?<birthdate>[0-9]{6})(?<birthcheck>[0-9]{1})(?<sex>[mfMF]{1})(?<expiredate>[0-9]{6})(?<expirecheck>[0-9]{1})(?<nacionality>[A-Za-z]{3})(?<optional>[a-zA-Z0-9<]{11})(?<linecheck>[0-9]{1})\\n(?<lname>[A-Z]+)(?<lname2><[A-Z]+){0,}<<(?<spacing>[<]{0,})(?<fname>[A-Z]+)(?<mname1><[A-Z]+){0,}(?<namecomplement>[a-zA-Z<]+){0,}', '')
const str = `IDCHES0002068<8<<<<<<<<<<<<<<<
8102287F1301014CHE<<<<<<<<<<<4
VADIS<<QUO<<<<<<<<<<<<<<<<<<<<
I<UTOD231458907<<<<<<<<<<<<<<<
7408122F1204159UTO<<<<<<<<<<<6
ERIKSSON<<ANNA<MARIA<<<<<<<<<<
I<NLDXI020DF236123456783<<<<<<
7208148F1108268NLD<<<<<<<<<<<9
VAN<DER<STEEN<<MARIANNE<LOUISE`;
// Reset `lastIndex` if this regex is defined globally
// regex.lastIndex = 0;
let m;
if ((m = regex.exec(str)) !== null) {
// 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