Created
February 5, 2018 09:54
-
-
Save rosuH/9a46b1eed6bb892687b88075804cb0b2 to your computer and use it in GitHub Desktop.
Regex_Java_Filter_out_special_symbols
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// global search REGEX | |
String regex="[^\\u4e00-\\u9fa5\\w]"; | |
Pattern pattern = Pattern.compile(regex); | |
Matcher matcher = pattern.matcher(data); | |
data = matcher.replaceAll(""); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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("")
: 用空字符替换掉找到的特殊字符。