How to remove empty results after splitting with regex in Java?

前端 未结 7 1606
臣服心动
臣服心动 2021-01-17 16:02

I want to find all numbers from a given string (all numbers are mixed with letters but are separated by space).I try to split the input String but when check the result arra

7条回答
  •  南笙
    南笙 (楼主)
    2021-01-17 16:13

    You can try with Pattern and Matcher as well.

    Pattern p = Pattern.compile("\\d+");
    Matcher m = p.matcher("asd0085 sa223 9349x");
    while (m.find()) {
        System.out.println(m.group());
    }
    

提交回复
热议问题