const regex = /OTHER REFERENCE:\s\d{8}\D{4}\s(?!\b(SHOPIFY)\b)\w+/g;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('OTHER REFERENCE:\\s\\d{8}\\D{4}\\s(?!\\b(SHOPIFY)\\b)\\w+', 'g')
const str = `OTHER REFERENCE: 20180201AIEJ SHOPIFY INTERNATIO SHOPIFY PMT AMT GBP 664367.38 |
OTHER REFERENCE: 20180201AJJS Shopify (Ireland) Limited SEPA Credit PMT AMT EUR 22718.08 |
OTHER REFERENCE: 20180301AIOV SHOPIFY INTERNATIO PMT AMT GBP 692673.45 |
OTHER REFERENCE: 20180302AKIH Shopify (Ireland) Limited SEPA Credit PMT AMT EUR 20147.37 |
OTHER REFERENCE: 20180226AJYS STRIPE DDA BACS PMT AMT GBP 122328.84 |
OTHER REFERENCE: 20180125AJDH STRIPE DDA BACS PMT AMT GBP 48392.41 |
OTHER REFERENCE: 20180103AGEJ STRIPE DDA BACS PMT AMT GBP 106257.89 | OTHER REFERENCE: 20180327AIQU STRIPE DDA BACS PMT AMT GBP 83725.34 |
(?m)^(?:(?!\\bSHOPIFY\\b).)+\$`;
// 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