Say I have a Scanner, and a user adds two words to that scanner.
There should be no space before the first word.
Only one space between the two words.
And no space after the second word.
i.e.
'hello world' is correct
but
'hello world bye'
' hello world'
'hello word '
'hello world'
are all incorrect.
I’ve tried to use regex, but with no success.
EDIT: Only letters a to z allowed (uppercase and lower)
try
I edited it to use the posix character class after you clarified that upper-case letters are also allowed.