Fix the problem when no hit at the end of the string.

Add another else if statement to avoid string not get pushed when there is no match at the end of the string.
Nicely done! This else if is a great way to cover that edge case of having no separator at the end of the string.