Skip to content

Instantly share code, notes, and snippets.

@rosuH
Created February 5, 2018 09:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rosuH/9a46b1eed6bb892687b88075804cb0b2 to your computer and use it in GitHub Desktop.
Save rosuH/9a46b1eed6bb892687b88075804cb0b2 to your computer and use it in GitHub Desktop.
Regex_Java_Filter_out_special_symbols
// global search REGEX
String regex="[^\\u4e00-\\u9fa5\\w]";
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(data);
data = matcher.replaceAll("");
@rosuH
Copy link
Author

rosuH commented Feb 5, 2018

What does this code do?

  • "[^\\u4e00-\\u9fa5\\w]" : Java Regex format, can find special symbols.
  • matcher.replaceAll("") : Replace thos special symbols with empty character.

这段代码的作用:

  • "[^\\u4e00-\\u9fa5\\w]" : Java 格式的正则表达式,用来匹配除了汉字、字母和数字以外的特殊字符
  • matcher.replaceAll("") : 用空字符替换掉找到的特殊字符。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment