PatternRegex

Find doubled words

The proofreading classic: a backreference that catches accidentally doubled words like "the the" — even across a line break.

Last updated

Patterngi
\b(\w+)\s+\1\b
Open in Regex Tester & Builder

Matches

  • It was was a mistake
  • The the report

Doesn’t match

  • the theory
  • over and over

Why it’s written this way

The parentheses capture a word; \1 demands the exact same text again after whitespace. That is the whole trick — a backreference matches what the group MATCHED, not what it could match.

The i flag makes the backreference case-insensitive too, so sentence-start doubles like "The the" are caught. \s+ spans newlines, which is exactly where doubled words hide after editing.

Edge cases to know

  • The trailing \b is load-bearing: without it, "the theory" would count as a double.
  • Legitimate doubles exist — "had had", "that that" — so this is a reviewing aid, not a safe auto-replace.
  • Words split by punctuation ("the, the") don't match; \s+ only crosses whitespace.

Related in Patterns