求一个正则表达式的写法,如何将一个字符串中的中文和字母分开?比如:“中国abc123”
用split以后得到String数组,第一个是“中国”,第二个是“abc123”

解决方案 »

  1.   

    split的话,你要设置一个分隔符的,必定对你的内容造成损失的。建议自己getChar来判断是否是26*2个字母+10个数字
      

  2.   

    /**
         * 
         * 返回非字母和数字 + 字母数字(26*2个字母 + 10个数字)
         * 诸如“中国abc123”将被分成“中国”和“abc123”
         * 而且约定中文总是在前的!
         * 
         * @param source
         * @return 2个字符串 
         */
        public static String[] splitter(final String source) {
            String[] tokens = null;
            int index = 0;
            for (int i = 0; source != null && i < source.length(); i++) {
                char c = source.charAt(i);
                System.out.println(i + ": " + c);
                System.out.println(">>>>" + Integer.toHexString(c));
                //判断受否字母和数字
                if ( (c >= '0' && c <= '9') 
                        || (c >= 'A' && c <= 'Z')
                        || (c >= 'a' && c <= 'z')) {
                    index = i;
                    break;
                }
            }
            
            //可以分组
            if (index > 0) {
                tokens = new String[] {source.substring(0, index), source.substring(index)};
            } else { //没有可分
                tokens = new String[] {source, null};
            }
            return tokens;
        }
      

  3.   

    1.getChar
    2.设定分割符
    3.split期待某高人的正则~:)
    顺便捞点分~
      

  4.   

    just have a try, not very sure....Pattern p = Pattern.compile("([\u4E00-\u9FA5]+)([0-9|a-z|A-Z]+)");
    while(m.find){
        String chinese = m.group(1);
        String num_letter = m.group(2);
    }
      

  5.   

    String str="reallyenglish 招聘Linux开发工程";
    String[] s=str.split("[\u4E00-\u9FA5]+");
      

  6.   

    chrisj() 的方法可行Pattern p = Pattern.compile("([\u4E00-\u9FA5]+)|([0-9|a-z|A-Z]+)");of course find() group(0);
      

  7.   

    to  takecare(大厅) :
    不可限定内容,内容包括字母数字和中文,具体情况无限制。但是看来只有用自己判断char的方法来做了。
    to dztc() :你的方法显然不行
      

  8.   

    Pattern p = Pattern.compile("([\u4E00-\u9FA5]+)([0-9|a-z|A-Z]+)");
    while(m.find){
        String chinese = m.group(1);
        String num_letter = m.group(2);
    }
    这个应该可以哦
      

  9.   

    Pattern p = Pattern.compile("([\u4E00-\u9FA5]+)([0-9|a-z|A-Z]+)");
    Matcher m = p.matcher(yourString);//之前少了这句
    while(m.find){
        String chinese = m.group(1);
        String num_letter = m.group(2);
    }难道我这个不行吗?
      

  10.   

    Pattern p = Pattern.compile("([\u4E00-\u9FA5]+)([0-9|a-z|A-Z]+)");
    Matcher m = p.matcher(yourString);//之前少了这句
    while(m.find){
        String chinese = m.group(1);
        String num_letter = m.group(2);
    }
    他的这个肯定行啊。。