Here is my regular expression : I want to replace string with empty value so that only unwanted characters left. Somehow it is returning the same string, not replacing any character defined in regular expression:
var regExpress = /^([a-zA-Z0-9!#%^*()\-\_+=|}{'";:\/.,\s]*)$/gi;
strMessage = strMessage.replace(regExpress, '');
what am I doing wrong ? I know it should be simple but unable to figure it out .
Remove
^and$. These are the markers of the beginning and end of the string.Without these, your method will only replace the characters when the whole string contains the characters as specified in the pattern.