Regex patterns/Text & extraction
Repeated word
A backreference catches the the kind of typo a spellchecker walks straight past.
/\b(\w+)\s+\1\b/giThe problem
Find places where the same word appears twice in a row — the commonest proofreading miss.
How it reads
Follow the line from left to right — every path you can trace is a string this pattern matches.
\b(\w+)\s+\1\bIn order:\bA word boundary — the edge between a word character and anything else(\w+)Capture group 1:\w+A word character (letter, digit or underscore), one or more times, as many as possible\s+Whitespace, one or more times, as many as possible\1The same text that group 1 captured earlier\bA word boundary — the edge between a word character and anything else
Matches
- This is is a test
- The the quick brown fox
- that that
Does not match
- A fine sentence
- a banana
- is island
Where it bites
- A backreference matches the *text* the group captured, not the pattern — which is why \1 here means "that same word again", not "another word".
- The trailing \b is essential: without it, "is island" matches, because the second word only has to start the same way.
- The i flag makes "The the" a hit. Drop it if capitalisation should count as a difference.