const regex = /[^&]_*\s*(SF)*\d{8}/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('[^&]_*\\s*(SF)*\\d{8}', 'gm')
const str = `_zz&69050398_5d147597dd4aca00014351d9_zz sf 76064603RPL_Import_Create
_zm&69396284_5d165ed60198d60001fbef9a_75946292_Import
_aa&69385775_5d15782bdd4aca0001435432_supplier_info_import_template
_aa&68936210_5d16581add4aca00014355e9_76005473 RPL_Import_Create_Stand_to_Package
_ac&68728692_5d18fa52dd4aca00014356dd_SF 76113839 Copy of Generic_Export_AdvancePR_result - 2019-06-30T200450.090`;
// 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