首页 > [JAVA]求一个验证 (数字,字母(不分大小写) ,中文汉字) 的正则表达式

[JAVA]求一个验证 (数字,字母(不分大小写) ,中文汉字) 的正则表达式

项目里面用到了分词,但是得到很多无关的分词,比如标点,各种符号之类的。

后来在黑名单里面加了中文停用词,能去除绝大部分,但是还是有一些奇奇怪怪的符号去不掉。

所以求一个正则:只能是 (数字,字母(不区分大小写),汉字)或其任意组合。

比如

  1. abcF
  2. as212
  3. das你好1d
  4. 34D4H好
  5. 大家

谢谢


\u4E00-\u9FA5\uF900-\uFA2D
加上
\w

    public static void main(String[] args) {
        // TODO implement RegexStuff.main
        String regex = "([\u4E00-\u9FA5\uF900-\uFA2D]|\\w)+";
        //Pattern pattern = Pattern.compile(regex);

        String str1 = "abcF";
        String str2 = "as212";
        String str3 = "das你好1d";
        String str4 = "34D4H好";
        String str5 = "大家";
        System.out.println(str1.matches(regex)); // true
        System.out.println(str2.matches(regex)); // true
        System.out.println(str3.matches(regex)); // true
        System.out.println(str4.matches(regex)); // true
        System.out.println(str5.matches(regex)); // true

    }

参考
http://blog.csdn.net/sww_simpcity/article/details/9082993

【热门文章】
【热门文章】