You could build a regular expression for this but a for
cycle will do just as good:
/**
* @return the rest of the input text from the first digit
*/
public String findPhone(String text) {
for (int i = 0; i < text.length(); ++i) {
if (Character.isDigit(text.charAt(i))) {
return text.substring(i);
}
}
return "";
}
And you can call it like:
String number = findPhone("Johannesburg General Hospital011 488 4911")
// number is 011 488 4911 here
String sanitizedNumber = number.replace(" ", ""); // number without spaces