how to remove the symbols such as ▼, >>,<< and others using the regex in javascript?
3 Answers
You can use the replace function for this, specifying the empty string as the replacement string. Here are a couple examples.
If you only want to strip specific characters:
s = s.replace(/[▼><]/g, '');
Or using a Unicode escape sequence:
s = s.replace(/[\u25bc><]/g, '');
If you want to strip all but alphanumeric characters:
s = s.replace(/[^A-Za-z0-9]/, '');
Edit: described Unicode escape sequence usage.
3 Comments
user495688
if i want to replace any symbol which possible appear in the browser,how i remove it?
BoltClock
@user495688: But all these characters appear on your browser.
user495688
i have remove all character var emailPattern = /[_a-zA-Z0-9\.]+@[^\.a-zA-Z0-9]+\.[a-zA-Z]+/gi; var urlPattern = /[a-z]+:\/\/[^\s]+/gi; var numberOrSymbolPattern = /[^0-9\.,!@#\$%\^\&*()`~_\-=\+|\\{}[]\s:;<>\?\/]+/gi; but when i testing my application there are some symbol which can't remove