Is it possible to use a regular expression to match all words but match unique words only once? I am aware there are other ways of doing this however I\'m interested
Exactly as maček's answer, but with an extra \b before the back-reference, otherwise if you had
glass shoes door window door glasses. window glasses sunglasses
You'd miss out a match for glasses as it finds it in the word sunglasses.
/(\w+\b)(?!.*\b\1\b)/
For search distinct words in multiline text use [\s\S]
instead of .
(\b\w+\b)(?![\s\S]*\b\1\b)
Pretty close, just readd the \b
in the negative lookahead
/(\w+\b)(?!.*\1\b)/
See it on Rubular