 <p>Split the string using a regex then loop through all elements, parse them to numbers and get the largest. </p> <p>Since <code>String.split()</code> requires you to provide a regex that matches the delimiters, i.e. in your case everything between digits, use the regex <code>\D+</code>, i.e. "a sequence of at least one non-digit character". Note though that <code>\d</code> matches non-ASCII digits as well, hence <code>\D</code> won't match those, so if you only want to parse ASCII digits you should use <code>[^0-9]+</code>.</p> <p>Rough example:</p> <pre><code>String[] elements = input.split("[^0-9]+"); for( String element : elements ) { //skip empty elements, see note if( element.isEmpty() ) { continue; } //parse and compare here } </code></pre> <p>One note: <code>String.split()</code> will not remove empty elements at the beginning of the array (e.g. when your starts with a non-digit character) thus you'd need to skip empty elements in the loop.</p>