const regex = /(([a-zA-Z-éÉèÈàÀùÙâÂêÊîÎôÔûÛïÏëËüÜçÇæœ'.]*\s)\d*(\s[a-zA-Z-éÉèÈàÀùÙâÂêÊîÎôÔûÛïÏëËüÜçÇæœ']*)*,)*\d*(\s[a-zA-Z-éÉèÈàÀùÙâÂêÊîÎôÔûÛïÏëËüÜçÇæœ']*)+,\s([\d]{5})\s[a-zA-Z-éÉèÈàÀùÙâÂêÊîÎôÔûÛïÏëËüÜçÇæœ']+/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('(([a-zA-Z-éÉèÈàÀùÙâÂêÊîÎôÔûÛïÏëËüÜçÇæœ\'.]*\\s)\\d*(\\s[a-zA-Z-éÉèÈàÀùÙâÂêÊîÎôÔûÛïÏëËüÜçÇæœ\']*)*,)*\\d*(\\s[a-zA-Z-éÉèÈàÀùÙâÂêÊîÎôÔûÛïÏëËüÜçÇæœ\']*)+,\\s([\\d]{5})\\s[a-zA-Z-éÉèÈàÀùÙâÂêÊîÎôÔûÛïÏëËüÜçÇæœ\']+', 'gm')
const str = `Apt. 120, 9 Quai de Caumartin, 21305 Tourcoing
8 étage, 229 Boulevard de Caumartin, 41224 Clichy
8116 Boulevard Pierre Charron, 51703 Bordeaux
9 Quai de Caumartin, 21305 Tourcoing
Apt. 901, 8431 Boulevard Vaneau, 85330 Mérignac
314 Passage de la Férronnerie, 76818 Villejuif
1 étage, 6645 Avenue des Grands Augustins, 47851 Lyon
Apt. 889, 301 Place Adolphe Mille, 04320 Issy-les-Moulineaux
Apt. 470, 147 Allée, Voie des Grands Augustins, 37097 Asnières-sur-Seine
Apt. 356, 1 Allée, Voie de l'Abbaye, 83865 Champigny-sur-Marne
`;
// 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