const regex = new RegExp('^\\[.*\\]\\n+((?:;;.*\\n+)+)', 'gm')
const str = `[TITLE]
[OPTIONS]
;;Options Value
;;------------------ ------------
FLOW_UNITS CFS
<MORE TEXT>
[PATTERNS]
;;Name Type Multipliers
;;-------------- ---------- -----------
;Daily pattern generated from time series '2-166:2-165 (obs)'. Average value was 0.0485 MGD.
2-166:2-165_(obs)_Daily DAILY 1.011 1.008 1.06 0.908 1.072 0.998 0.942
<MORE TEXT>
[COORDINATES]
;;Node X-Coord Y-Coord
;;-------------- ---------------- ----------------
<MORE TEXT>
[JUNCTIONS]
;; Invert Max. Init. Surcharge Ponded
;;Name Elev. Depth Depth Depth Area
;;-------------- ---------- ---------- ---------- ---------- ----------
1-1 837.85 15.25 0 0 0
<MORE TEXT>
[REPORT]
INPUT YES
CONTROLS NO
<MORE TEXT>`;
// 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