Regex - only allow a space or nothing after a match
David Brabant is close, but I think you actually want to try ending your regular expression with (?!\S)
- this will mean you'll match anything not followed by a non-whitespace character. If you just want to match on spaces rather than whitespace, use (?![^ ])
.
Use negative look ahead:
(\w+)(\.*)(\(\))+(\s)*(?!.)
The important part for you in the regex above is: (\s)*(?!.)
(\s)* : followed by 0 or more white spaces (?!.) : and no other character