TEST

来源:互联网 发布:一个都不能少影评知么 编辑:程序博客网 时间:2024/06/06 13:13
private static  String getImo(String str){
 if(checkIMO(str)){
  char a  = str.charAt(str.length()-1);
  if(Character.isLetter(a)){
   String newStr = str.substring(0,str.length()-1);
   return newStr;
  }
 }
 return str;
}
 
private  static boolean checkIMO(String string){
 if (string.endsWith(".")) {
  return false;
 }
 String[] result = string.split("[.]");
 if (result.length>2) {
  return false;
 }
 Pattern p = Pattern.compile("^\\d{1,2}$");
 Pattern p2 = Pattern.compile("^[0-9]{1}[a-zA-Z]?$");
 if (p.matcher(result[0]).find()&&result.length==1) {
  return true;
 }
 
 if (p.matcher(result[0]).find()&&result.length==2&&p2.matcher(result[1]).find()) {
  return true;
 }
 return false;
}
原创粉丝点击