const regex = /[\n\s\'\"](<ins[^<]+class=[\"'\\'\\"][^<]*\s*dcmads\s*[^<]*[\"'\\'\\"][^<]+>)/g;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('[\\n\\s\\\'\\"](<ins[^<]+class=[\\"\'\\\\\'\\\\"][^<]*\\s*dcmads\\s*[^<]*[\\"\'\\\\\'\\\\"][^<]+>)', 'g')
const str = `<script type="text/adtag">
<ins class='dcmads' style='display:inline-block;width:160px;height:600pxn'
data-dcm-placement='N7310.468584.AMNETGROUPINC./B9750164.132175790'
data-dcm-rendering-mode='iframe'
data-dcm-https-onlyn
data-dcm-resettable-device-id=''>
<script src='https://www.googletagservices.com/dcm/dcmads.js'></scr+ipt>
</ins>
</script>
this.tagsrc = '<ins class=\\'dcmads\\' style=\\'display:inline-block;width:160px;height:600px\\'\\n data-dcm-placement=\\'N7310.468584.AMNETGROUPINC./B9750164.132175790\\'\\n data-dcm-rendering-mode=\\'scr'+'ipt\\'\\n data-dcm-https-only\\n data-dcm-resettable-device-id=\\'\\'>\\n <scr'+'ipt src=\\'https://www.googletagservices.com/dcm/dcmads.js\\'></scr'+'ipt>\\n</ins>';
this.tagsrc = '<ins class=\\'dcmads\\' style=\\'display:inline-block;width:160px;height:600px\\'\\n data-dcm-placement=\\'N7310.468584.AMNETGROUPINC./B9750164.132175790\\'\\n data-dcm-rendering-mode=\\'scr'+'ipt\\'\\n data-dcm-https-only\\n data-dcm-resettable-device-id=\\'\\'>\\n <scr'+'ipt src=\\'https://www.googletagservices.com/dcm/dcmads.js\\'></scr'+'ipt>\\n</ins>';
<script type="text/adtag">
<ins class='dcmads' style='display:inline-block;width:160px;height:600px'
data-dcm-placement='N7310.468584.AMNETGROUPINC./B9719431.131720722'
data-dcm-rendering-mode='script'
data-dcm-https-only
data-dcm-resettable-device-id=''>
<script src='https://www.googletagservices.com/dcm/dcmads.js'></scr+ipt>
</ins>
</script>
<script language="javascript" type="text/javascript" src="https://cdn.doubleverify.com/dvbs_src.js?ctx=919838&cmp=9719431&plc=131720722&sid=1201527&dvregion=0&unit=160x600">
</script>`;
// 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