Is it possible to extract the unmatched results from a Regexp and store them in an array (essentially reversing the match)?
The following code partially addresses this issue using the replace method:
str = 'Lorem ipsum dolor is amet <a id="2" css="sanitizer" href="#modal-collection" data-toggle="modal" data-target="#ae" data-toggle="modal" data-attr-custom="test">Lorem ipsum </a> the end';
let elementRegexp: RegExp = new RegExp('<([^>]+?)([^>]*?)>(.*?)>', 'g');
let text = str.replace(elementRegexp, '');
let matchElements = str.match(elementRegexp);
console.log(text);
// Output: Lorem ipsum dolor is amet the end
console.log(text);
// Output: ["<a id="2" css="sanitizer" href="#modal-collection"...=modal" data-attr-custom="test">Lorem ipsum </a>"]
Expected result:
["Lorem ipsum dolor is amet", "the end"]