谁能给个匹配汉字,数字,字母或下划线组成的字符串的正则表达式?我写这个为什么不对啊?(\\w|[\u4e00-\u9fa5]|_)*

解决方案 »

  1.   

    需要转义一下特殊字符
    (\\x[\\u4e00-\\u9fa5]\\w)*
      

  2.   

    更正一下
    [[\\u4e00-\\u9fa5]\\w]*
      

  3.   

    public static void main(String[] args) {
    String s="你好Hello_World123世界你好Hello_World123世界你好Hello_World123世界";
    System.out.println(s.matches("[\\w*|[\u4e00-\u9fa5]*]*")); }
    试试
      

  4.   

    * 匹配中文字符的正则表达式: [\u4e00-\u9fa5]
    * [a-zA-Z]*:表示英文字母有0个或多个
    * \\d*:表示数字有0个或多个
      

  5.   

    答:String reg="[\\w\\u4e00-\\u9faf]+";   就行了。