It looks like you’re attempting to match against <>
and not <>
. In addition, back slashes must be escaped within the RegExp constructor.
Therefore:
function regex() {
let str1= "TT-DD-11-AZR\"><img src=x onerror=alert(1)>"
let regex = new RegExp("<img([\\w\\W]+?)>", "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]