I used the following expression
str.match(tag+"(\s*=\s*)((['"]*)(.+?)(['"]*)\1)");
where str is the string to be matched with and tag is a variable
For example the above expression should match
m="img"
m='img'
where tag=m;
But at the above mentioned lined I'm getting
SyntaxError: Unexpected token ]