My code sample is as the following:
let str = '<p>test xss<img src=x onerror=alert(1)><h1 onmouseover=prompt(0)></h1></p>';
console.log(str.replace(/(<img [\s\S]*>?|<h1 [\s\S]*><\/h1>)/i, ''));
My purpose is very clear: extract img and h1 tag from str, so I expect the result is <p>test xss</p>, but actually the result is <p>test xss. It seems the regexp string img judgement part match the end of str. Can anyone tell me how to write this regexp string correctly ?