const regex = new RegExp('(?x)^(?P<crt>crt)
(?:
(?:
(?:_) (?P<sm>start_mode)(?P<ul>_)?(?P<smq>(?(ul)normal|ep))
| (?:
(?P<bool>[01])\\B
(?:_
(?:
(?: (?P<dual>dual(?P<dq>ch))
| (?P<ext>extended)(?P<q>ch|da|ep)
| (?P<std>standard)
| (?P<bstr>\\w*)) ) | )
| (?: (?: (?P<digit>[2-9])(?:_)(?P<str>\\w*))) )
)
)$', 'gm')
const str = `crt_start_mode_normal
crt_start_modeep
crt0_dualch
crt0_abc
crt1_xyzzy
crt2_abc
`;
// 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