取出一个字符串中的所有数字并不难,但是怎么分组取出这些数字呢?比如:123和234以及1255,这样一个字符串,需要取出来的结果为 : 123、234、1255,而不是取出单个数字或取出的结果集为全部数据。

Pattern p = Pattern.compile("-?\\d+");
Matcher m = p.matcher("There are more than -2 and less than 12 numbers here");
while (m.find()) {
  System.out.println(m.group());
}

  如上代码,打印结果为 -2和12两个结果。

相关文章:

  • 2022-02-05
  • 2022-12-23
  • 2021-06-14
  • 2022-02-09
  • 2022-12-23
  • 2022-12-23
  • 2021-12-25
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-07-26
  • 2022-12-23
  • 2020-05-20
  • 2022-12-23
  • 2021-08-03
  • 2022-12-23
相关资源
相似解决方案