const regex = new RegExp(' (?s)
<page>
(
.*?
(?:
(?: <page> | </page> )
(*SKIP) (*FAIL)
| {{Infobox
)
.*?
)
(?: <page> (*SKIP) (*FAIL) | </page> )
', 'g')
const str = `List of keywords :
keyword1 = <page>
keyword2 = </page>
keyword3 = {{Infobox
Example A:
<page>
text to consider without {{ not-Infobox
</page>
Result => do not extract (or keep or split) this part.
Example B:
<page>
text to consider with {{Infobox here}}
</page>
Result => extract (or keep or split) this part.`;
const subst = `$1`;
// 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