I have this regex now:
((\b(Example|Overflow|Test)\b)\s*(?!.*\2))+
This matches the predefined words, up until a word is already used (if any). See below (matches in bold) for several examples:
- Example Overflow Test Overflow
- Example Overflow Test
- Just an Example Overflow
- Example another Overflow
This is doing what I ask it to, but I want to special case the 2nd example (Example Overflow Test). If the entire string is matched (from start to end), I don't want to match the first word anymore. So 2. should instead match "Example Overflow Test". My original regex has many more words, so I'd like to avoid repeating these and instead refer back to the same capture group similar to how I already check if a word is already used before.