SyntaxFix
Write A Post
Hire A Developer
Questions
You can also use java.util.Scanner:
java.util.Scanner
new Scanner(str).useDelimiter("[^\\d]+").nextInt()
You can use next() instead of nextInt() to get the digits as string.
next()
nextInt()
You can check for the presence of number using hasNextInt() on the Scanner.
hasNextInt()
Scanner