I have tried the following but it doesn’t work:
console.log('aaaa dfdd |!|'.search(/|!|/g));
if(/|!|/g.test("abcd |aaa!|")) alert('true');*
>Solution :
Both | and ! are special characters in regular expressions, so you need to escape them:
if(/\|\!\|/g.test("abcd |aaa!|")) alert('wrong');
if(/\|\!\|/g.test("abcd |aaa|!|")) alert('correct');