日期:2014-05-20 浏览次数:20958 次
public static void main(String[] args) throws IOException { String str = "123456三四五六七八十738912345一6789012六35678901一二三四五六一一"; String regex1 = "(?=(?:[^\u0000-\u00ff]*[\u0000-\u00ff][^\u0000-\u00ff]*){0,32}$).{0,48}"; String regex2 = "(?=(?:[\u0000-\u00ff]*[^\u0000-\u00ff][\u0000-\u00ff]*){0,16}$).{0,48}"; System.out.println(str.matches(regex1)); System.out.println(str.matches(regex2)); System.out.println(str.length()); char[] cs = str.toCharArray(); int a = 0, b = 0; for(char c : cs) { if(c > 0xff){ b++; }else{ a++; } } System.out.println("半角个数:" + a + ",全角个数:" + b); }