Extract digits from string - StringUtils Java

前端 未结 18 1226
忘掉有多难
忘掉有多难 2020-12-01 09:06

I have a String and I want to extract the (only) sequence of digits in the string.

Example: helloThisIsA1234Sample. I want the 1234

It\'s a given that the s

18条回答
  •  被撕碎了的回忆
    2020-12-01 09:17

    Try this approach if you have symbols and you want just numbers:

        String s  = "@##9823l;Azad9927##$)(^738#";
        System.out.println(s=s.replaceAll("[^0-9]", ""));
        StringTokenizer tok = new StringTokenizer(s,"`~!@#$%^&*()-_+=\\.,>

提交回复
热议问题