const regex = /^(?:.*?\x7C){14}(?'champs1'.*?)\x7C(?:.*?\x7C){6}(?'champs2'.*?)\x7C(?'champs3'.*?)\x7C/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('^(?:.*?\\x7C){14}(?\'champs1\'.*?)\\x7C(?:.*?\\x7C){6}(?\'champs2\'.*?)\\x7C(?\'champs3\'.*?)\\x7C', 'gm')
const str = `1906823505|BPA|CORENC-BPAUR0133|LR35788G|LEONETTI CATHERINE|04.76.88.14.14||INT|MG_ENS_010002|Ensemble Chauffage-Climatisation||MNT|MG116|05/06/2019 17:36:00|06/06/2019 10:36:00|4|FR|05/06/2019 16:36:00|BPA|CORENC-BPAUR0133|LR35788G|BPAURA-ENGIE LOIR|ENGIE COFELY LOIRE|0|||313|002|A1 - ESPACE 4|0|BP AUVERGNE RHONE ALPES (CORENC-BPAUR0133)|2 AVENUE DU GRESIVAUDAN||38700|CORENC|0438884619||||1906823505|merci d'intervenir pour rétablir la clim à l'agence`;
// 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