Duplicate Word in GO
Go (RE2) can't run this pattern out of the box.
Try it in the GO tester →Why it doesn't work in GO
Go's RE2 engine doesn't support backreferences (`\1`, `\2`, …) for the same linear-time reason.
Workaround
Match the candidate substring with a single capture, then verify the duplication in code; or use JS / Python which both support backreferences.
Pattern
regexGO
\b(\w+)\s+\1\b (flags: gi)How the pattern works
`\b(\w+)\b` captures a word. `\s+\1\b` matches whitespace followed by the same word (backreference `\1`). Case-insensitive.
Examples
Input
the the cat sat on the the matMatches
the thethe the
Input
no duplicates hereNo match
—