const regex = /^(\S+)\h+(\S+)\h+(\w+(?:\h\w+)*(?:\h*\([^)]+\)(?:\h\w+)?)?)(?:\h{2,}(\S+))?$/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('^(\\S+)\\h+(\\S+)\\h+(\\w+(?:\\h\\w+)*(?:\\h*\\([^)]+\\)(?:\\h\\w+)?)?)(?:\\h{2,}(\\S+))?$', 'gm')
const str = `SIG.SND.SERV ZOS FD MCA LPAR (MCA - NDMSRV LOCAL)
ADC1 ZOS AMEX SSL
ADEPTRA.GB1.PROD LINUX FICO (ADEPTRA) LTD TLS
ADEPTRA.GB2.CQA LINUX FICO (ADEPTRA) LTD TLS
AIX.EG3C UNIX BARCLAYS S+
AIX.EG3P UNIX BARCLAYS S+
AIX.RMWDEV1 UNIX FDCS
AIX.RMWPROD1 UNIX FDCS
AIX-EFXWRWCK01 UNIX EQUIFAX EUROPE
ANB-DRC-CDFDI NT ARAB NATIONAL BANK (ANB) SSL
APPDGVIRTUAL23F NT LTSB MAIL AND DISTRIBUTION
APPLCOND MVS CIM ITALIA (FOR BNL)
APPLGVIRTUAL0FA NT LTSB MAIL AND DISTRIBUTION TLS
APPLGVIRTUAL191 NT LTSB MAIL AND DISTRIBUTION TLS`;
// 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