ublic class Test9
{
public static void main(String[] args)
{
String regEx1 = "[\\u4e00-\\u9fa5]";
String regEx2 = "[a-z||A-Z]";
String regEx3 = "[0-9]";
String str = "1 2fdAsz我是hhhZ大傻逼";
String s1 = matchResult(Pattern.compile(regEx1),str);
String s2 = matchResult(Pattern.compile(regEx2),str);
String s3 = matchResult(Pattern.compile(regEx3),str);
System.out.println(s1+"\n"+s2+"\n"+s3);
}
public static String matchResult(Pattern p,String str)
{
StringBuilder sb = new StringBuilder();
Matcher m = p.matcher(str);
while (m.find())
for (int i = 0; i <= m.groupCount(); i++)
{
sb.append(m.group());
}
return sb.toString();
}
}
---------------------
java提取字符串中汉字、数字、字母
最新推荐文章于 2024-07-07 03:13:51 发布