I think you have understood how you got until 5 in output.6 is in output because find() method returns true for zero or more occurrences of a digit. and at last of the input find() considers zero length match and true is returned by the find() and start() blindly returns 6 even though there are no those many character in input. i hope you will understand from this explanation.