2

how to remove the symbols such as ▼, >>,<< and others using the regex in javascript?

1
  • 1
    You really need to accept more answers. Commented Dec 23, 2010 at 5:12

3 Answers 3

2

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.

Sign up to request clarification or add additional context in comments.

3 Comments

if i want to replace any symbol which possible appear in the browser,how i remove it?
@user495688: But all these characters appear on your browser.
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
1

I'd remove non-standard character(s) by using the unicode token \u and the corresponding character code.

For example:

// Remove "▼" using its character code
var s = "I like milk ▼.".replace(/\u9660/g, "");

Comments

0

You can use replace(/[\u0100-\uffff]/g, '') to remove characters outside the extended ASCII range.

E.g.

>>> "I 𝔻Ȯ𝓝ʼṮ like ȖŋŀℭỚ𝕯Ễ Regexs‽‽‽".replace(/[\u0080-\uffff]/g, '')    
"I like Regexs"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.