const regex = /^La.+?no\s*(?'num_externe'.+?)\s.*\s(?:^.*\n)*.*installation\s*:\s*(?'ins_numins'.+?)\s+.*:\s*(?'apt_localisation'.+?)\s+.*:\s*(?'apt_nom'.+?)\s+.*:\s*(?'apt_email'.*?)\s+Typologie:.*\s*Motif.+?:\s*(?'qsy_lib'.+?)\s*Demande:\s*(?'commentaire_externe'.+)/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('^La.+?no\\s*(?\'num_externe\'.+?)\\s.*\\s(?:^.*\\n)*.*installation\\s*:\\s*(?\'ins_numins\'.+?)\\s+.*:\\s*(?\'apt_localisation\'.+?)\\s+.*:\\s*(?\'apt_nom\'.+?)\\s+.*:\\s*(?\'apt_email\'.*?)\\s+Typologie:.*\\s*Motif.+?:\\s*(?\'qsy_lib\'.+?)\\s*Demande:\\s*(?\'commentaire_externe\'.+)', 'gm')
const str = `Demandes - Date: 03/06/2019 à 09:58
La demande no 117530 a été externalisée à NORD ENGIE-Cofély,
Site concerné:
- Numéro d'installation : 2870521005
- Nom du Site : APE ST YRIEIX
Chargé d'affaire: Aurelie GUILLON
Email:
Typologie: Forfait heures multiservices
Motif détaillé: Demande
Demande: Objet : fixer la boîte à pharmacie petit format au mur. Bonjour, Je sollicite une intervention pour fixer la boîte à pharmacie petit format au mur en zone d'accueil à côté de l'extincteur. Cordialement. Sylvain CLUZEAU.
`;
// 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