public static void main(String[] args) {
Pattern pattern =null;
String content = "30.年前";
if(content.contains(".")){
pattern = Pattern.compile("^(\\d+.{0,1})(.*)");
}else{
pattern = Pattern.compile("^(\\d+)(.*)");
}
Matcher matchers = pattern.matcher(content);
if (matchers.matches()) {//数字开头
//System.out.println(matchers.group(1));// =30
//System.out.println(matchers.group(2));// =年前
}
}
判断一个string是否以数字开头
最新推荐文章于 2021-09-10 11:28:32 发布