[Solved] Regular expression to find the exact match for tag in a string.- JS [closed]


It looks like you’re attempting to match against <> and not &lt;&gt;. In addition, back slashes must be escaped within the RegExp constructor.

Therefore:

function regex() {
    let str1= "TT-DD-11-AZR\"&gt;&lt;img src=x onerror=alert(1)&gt;"
    let regex = new RegExp("&lt;img([\\w\\W]+?)&gt;", "g");
    const match = regex.exec(str1);
if (match) { //this comes as null
   return match;
}
}

console.log(regex())

solved Regular expression to find the exact match for tag in a string.- JS [closed]