How to extract the first number from string in Java

1 Answer

0 votes
public class MyClass {
    public static void main(String args[]) {
        String s = "412hjdsf72q1p0on8mqjava9953";

        String n = s.split("(?=\\D)")[0];

        System.out.println(n);
    }
}




/*
run:

412

*/

 



answered Dec 15, 2020 by avibootz
...