const regex = /(?s)^SCHEDULE(?:.(?!^END$))*?#\/[^\r\n]*E\r?\n(?:(?!^$).)*?[ \t]*NOP$.*?^END$/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('(?s)^SCHEDULE(?:.(?!^END$))*?#\\\/[^\\r\\n]*E\\r?\\n(?:(?!^$).)*?[ \\t]*NOP$.*?^END$', 'gm')
const str = `
SCHEDULE MASTERAGENTS#KA0HM00_LEASE
DESCRIPTION "Added by composer."
:
CLA0HDST01#/KA0H/KA0HM00_LEASE/KA0HM010_LEASE_AFT
FOLLOWS KA0HM003_LEASE
FOLLOWS KA0HM007_LEASE
CLA0HDST01#/KA0H/KA0HM00_LEASE/KA0HM006_LEASE
FOLLOWS KA0HM004_LEASA
NOP
MASTERAGENTS#/KA0H/KA0HM00_LEASE/KA0HM00SLEASE
CLA0HDST01#/KA0H/KA0HM00_LEASE/KA0HM003_LEASE
CLA0HDST01#/KA0H/KA0HM00_LEASE/KA0HM002_LEASE
FOLLOWS KA0HM001_LEASE
CLA0HDST01#/KA0H/KA0HM00_LEASE/KA0HM001_LEASE
FOLLOWS KA0HM00S_LEASE
MASTERAGENTS#/KA0H/KA0HM00_LEASE/KA0HM00E_LEASE
FOLLOWS KA0HM010_LEASE_AFT
CLA0HDST01#/KA0H/KA0HM00_LEASE/KA0HM004_LEASE
FOLLOWS KA0HM002_LEASE
CLA0HDST01#/KA0H/KA0HM00_LEASE/KA0HM009_LEASE
FOLLOWS KA0HM004_LEASE
END
`;
// 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