复制代码
String str = "123abc";
String pattern = "^\\d{0,}";

  Pattern r = Pattern.compile(pattern);
  Matcher m = r.matcher(str);
  //m.matches()  //是否匹配
  if(m.find()) {
   System.out.println(m.group());
  }
复制代码

一个挺好用的正则表达式网站:https://c.runoob.com/front-end/854