The below script is returning null. It is returning correctly if I remove round brackets in str and patt1 for the text spot_Northeast(300)_comment
<script type="text/javascript">
var str="0000CentralGasEform2,0000CentralGasEformNew,spot_Northeast(300)_comment";
var patt1=/\bspot_Northeast(300)_comment/g;
document.write(str.match(patt1));
</script>
In my application, the value in str is taken from the cookies and the value in patt1 is dynamic based on the window opened
regExp = new RegExp('\\b'+FormOpen+'\\b', 'g');
Here FormOpen is dynamic. Then I replace the match in cookie
var temp=CookieList.replace(regExp,"");
Is there a way to tell RegEX that () is normal text instead of hardcoding?
escape them
var patt1=/\bspot_Northeast\(300\)_comment/g;() are reserved characters in the context (.*) for instance, you need to tell the regex engine to treat them as normal text through a process called escaping