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

前端 未结 7 1605
臣服心动
臣服心动 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:08

    The method i think to solve this problem is,

    String urStr = "asd0085   sa223 9349x";
    urStr = urStr.replaceAll("[a-zA-Z]", "");
    String[] urStrAry = urStr.split("\\s");
    
    1. Replace all alphabets from the string.
    2. Then split it by whitespace (\\s).

提交回复
热议问题