const regex = /(?<!(?:\\{2})*\\)(?:(?<begin_capture>[\(])(?<begin_capture_modifier>(?=[<][a-z_A-Z]+[>])|(?!\?(?:<?[=!]|:)))|(?<begin_non_capture>\((?=\?(?:<?[=!]|:))))|(?:(?<end>\)))/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('(?<!(?:\\\\{2})*\\\\)(?:(?<begin_capture>[\\(])(?<begin_capture_modifier>(?=[<][a-z_A-Z]+[>])|(?!\\?(?:<?[=!]|:)))|(?<begin_non_capture>\\((?=\\?(?:<?[=!]|:))))|(?:(?<end>\\)))', 'gm')
const str = `// Basic - Repeat Delimiters
/^((?:([gimsuy])(?!.*\\\\2))*)/gm
// Basic - Nested - Captured | Non-captured
^(?:(// +)(?:(@noframes)([ \\t]*\$)|(@(?:include|match|grant|require))([\\t ]+)(?:(https?.+?)|(.+))(\\**)([ \\t]*)|(^//[ \\t]+)(@(?:author|name(?:space)?|version|description))([ \\t]+)(.+?)([ \\t]*)|(^//[ \\t]+)(@resource)([ \\t]+)(\\S+)([ \\t]+)(\\S+)([ \\t]*))(\\n(?://[ \\t]*\\n)*))
// Basic - Captured | Non-captured | Lookbehind Positive
(?<=^[ \\t]*)(//)([ ])(?<capture_name>)(Case:)([ \\t]+)(.*\\S)([ \\t]*)?\$
// Complex
(?<=^[ \\t]*)(//)([ ])(Case:)([ \\t]+)(.*\\S)([ \\t]*)?\$
^(?:(?:(?:[0]*|[0]*1)(?=\$))|(?:(?:[0]*|[0]*1(?[1-9]+)))?[\\.][\\d]+)\$
^((?:[ ]{2})*[ ])([#])([ ]+)(?:(@param)([ ]+)(?:([\\\$][\\d\\*@\$?&]+))(\\??)(?:(:)([\\t ]+)(\\w+))?(?:([ ]+)([=][>])([ ]+)(?:([A-Za-z_-](?:[<][^\\n>]+[>]|[A-Za-z_-]*[^\\n]*?))(?:([ ]+)(?:(@desc)|([<]\\?))([ ]+)(.+?))?))([ ]*)|(@return)(?:([ ]+)([=][>])([ ]+)(?:([A-Za-z_][A-Za-z_]*)(.*?)(?:([ ]+)(?:(@desc)|([<]\\?))([ ]+)(.+?))?)))\$`;
const subst = `\n - $begin_capture`;
// The substituted value will be contained in the result variable
const result = str.replace(regex, subst);
console.log('Substitution result: ', result);
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