Duplicate Word
Detects consecutive duplicate words using a backreference.
Try it in RegexPro →Available in
Pattern
\b(\w+)\s+\1\b (flags: gi)Raw source: \b(\w+)\s+\1\b
How it works
Examples
Input
the the cat sat on the the matMatches
the thethe the
Input
no duplicates hereNo match
—Common use cases
- •Proofreading
- •Content editors
- •Writing-quality linters
Related patterns
Word Boundary (Whole Word Match)
Text ProcessingMatch the whole word `cat` without matching it inside other words like `concatenate` or `category`.
Negative Lookahead
Text ProcessingUse negative lookahead `(?!...)` to match words that are NOT in a blocklist (here: log-level keywords).
Single-Line Comment (// or #)
Text ProcessingMatch single-line comments using either the `//` (C-family) or `#` (shell, Python, Ruby, YAML) marker.
Base64 String
Text ProcessingMatch Base64-encoded strings, including proper padding with = and == characters.
Related concepts
Word Boundaries: \b and \B
Concept\b matches the position between a word character and a non-word character. It keeps your regex from matching 'cat' inside 'concatenate.'
How to Replace Text Using Regex in JavaScript
How-toString.replace and String.replaceAll accept a regex. Use the g flag for multi-match replace, $1/$2 for capture references, and a function for complex logic.