Data & Formatting · In-Browser Regular Expression Lab
Duplicate Words Regex — Find and Remove Consecutive Repeated Words
Finds repeated words separated by whitespace like 'the the' or 'is is' using backreferences.
Flags:
//gi
Match Found
Load Sample:
Match Inspection & Details1 match
Match #1:the the
Test Samples Verification Matrix
Expected Valid Samples (Should Match)
the the company Pass
this is is great Pass
we we went Pass
Expected Invalid Samples (Must Reject)
the company Rejected (Pass)
this is great Rejected (Pass)
very good Rejected (Pass)
Code Implementation Generator
// JavaScript / TypeScript (ES6+)
const pattern = /\b(\w+)\s+\1\b/gi;
const text = "the the company";
const isMatch = pattern.test(text);
console.log("Is Match:", isMatch);
if (isMatch) {
const matches = text.match(pattern);
console.log("Matches:", matches);
}Regular Expression Token Breakdown
Captures a word with `(\w+)` and checks if it is immediately followed by the exact same word via `\1`. Each component of the regular expression serves a distinct syntactical purpose as mapped below:
| Token Pattern | Name / Component | Function & Rule |
|---|---|---|
| \b | Word boundary | Prevents partial word matches. |
| (\w+) | Word Group | Captures word characters into group 1. |
| \s+ | Whitespace | One or more spaces or linebreaks. |
| \1 | Backreference | Matches the exact contents of group 1. |
Frequently Asked Questions
How to replace with a single instance?
Related Regular Expressions
Browse All 40 PatternsData & Formatting
Leading & Trailing Whitespace
Matches beginning and ending spaces, tabs, and newlines for string sanitization.
/^\s+|\s+$/gTest regex
Code & Markup
Markdown Links Parser
Captures anchor text and target URL from Markdown link syntax `[text](url)`.
/\[([^\]]+)\]\((https?:\/\/[^\s\)]+)\)/gTest regex
Code & Markup
HTML Tags Matcher & Stripper
Matches HTML markup tags for sanitization, stripping, or token extraction.
/<\/?[a-zA-Z][a-zA-Z0-9]*(?:\s+[^>]*?)?\/?>/gTest regex