/** * Returns the trailing integer from the given string or null if the string * does not end with number Example: Alice has got a cat 12 - will return 12 * (the position of '1') Alice has got a black cat - will return null (no * trailing number in the string) */ public static String getTrailingInteger(String str) { int positionOfTrailingInteger = getPositionOfTrailingInteger(str); if (positionOfTrailingInteger == -1) { // string does not end in digits return null; } return str.substring(positionOfTrailingInteger); }