const regex = /(?s)Form.*?\K\d{9}(?=.*?FMLA)/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('(?s)Form.*?\\K\\d{9}(?=.*?FMLA)', 'gm')
const str = `Form ( For Medical Leaves of Absence ) DO NOT return this document with your original request for a leave of absence . Please email or fax this document to the HR Service Center 5 - 7 days before the date you're expected to return to work .
SECTION I : To be completed by Associate Associate's Name : Associate's Job Title : Associate ID ; Location / Store # James Doe Garden Associate 123456789 SECTION II : To be completed by a health care provider treating the associate / patient : Your patient is currently on leave of absence . Answer , fully and completely , all applicable parts . Several questions seek a response as to the frequency or duration of a condition , treatment , etc. Your answer should be your best estimate based upon your medical knowledge 1 , experience , and examination of the patient . Be as specific as you can ; terms such as "" lifetime , "" or "" indeterminate "" may not be sufficient to determine FMLA coverage .`;
// 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