Yeah, if the input cannot contain spaces one can think of various short ways. In yours, by the way, you should check what's before (\S+) and after \1, to avoid errors with strings like "air battle lemon". The regex should look something like this:
/(?:^| )(\S+) \1(?:$| )/