日期:2014-05-20  浏览次数:20823 次

正则表达式提取类名
字串   包名.类名   如: "com.csdn.net.MyClass "     想用正则提取类名(MyClass)如何写正则表达式?

------解决方案--------------------
System.out.println(s.substring(s.lastIndexOf( ". ")+1));

------解决方案--------------------
String str = "com.csdn.net.MyClass ";
StringTokenizer token = new StringTokenizer(str, ". ");
System.out.println(token.countTokens());
while(token.hasMoreTokens()){
String ss = token.nextToken();
Pattern pattern = Pattern.compile( "^[A-Z]{1}+([a-zA-Z])*$ ");
Matcher matcher = pattern.matcher(ss);
if(matcher.find()){
System.out.println(ss);
}
}