const regex = /TRN.*FRLPD\s+FRPLY.*\s*FRLPD\/([\w\s]*).*FRPLY\/([\w\s]*)\//igm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('TRN.*FRLPD\\s+FRPLY.*\\s*FRLPD\\\/([\\w\\s]*).*FRPLY\\\/([\\w\\s]*)\\\/', 'igm')
const str = `1.TORNEAMPLE/ERIC
2 HHL RT HK1 LYS IN23NOV OUT26NOV PAST
3 TRN 2C 87 6609 AF 31DEC 1 FRPLY FRLPD HK PAST *
4 TRN 2C 87 6628 AF 01JAN 4 FRLPD FRPLY HK1 1800 2007
FRLPD/LYON PART DIEU//FRPLY/PARIS GARE LYON /TGD *
5 MIS 1A HK1 PAR 23MAY-ARCHIVAGES
6 AP 04.74.07.68.39`;
// 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