Regex for Repeated Words
Regex Pattern
\b(\w+)\s+\1\bDetects consecutive duplicate words (e.g. "the the")
Quick Answer
The regex pattern for repeated words is `\b(\w+)\s+\1\b`. Detects consecutive duplicate words (e.g. "the the"). This works in JavaScript, Python, Ruby, PHP, Java, and most regex engines that support PCRE syntax.
Test Examples
| Input | Result |
|---|---|
| the the quick fox | ✓ Matches |
| is is broken | ✓ Matches |
| very very good | ✓ Matches |
| the quick fox | ✗ No match |
| no repeats here | ✗ No match |
| their there | ✗ No match |
Code Examples
javascript
const regex = /\b(\w+)\s+\1\b/; const isValid = regex.test(value);
python
import re
pattern = r'\b(\w+)\s+\1\b'
if re.match(pattern, value):
print("valid")ruby
pattern = /\b(\w+)\s+\1\b/ if value =~ pattern puts "valid" end
php
if (preg_match('/\b(\w+)\s+\1\b/', $value)) {
echo "valid";
}java
String pattern = "\\b(\\w+)\\s+\\1\\b"; boolean isValid = value.matches(pattern);
Frequently Asked Questions
Related Regex Patterns
Markdown Heading
Markdown heading (# to ######)
Markdown Link
Markdown inline link [text](url)
Markdown Image
Markdown inline image 
Markdown Bold
Markdown bold text (**text** or __text__)
Markdown Code Block
Markdown fenced code block opening/closing delimiter
camelCase Word
camelCase identifier (starts lowercase, no separators)