File tree Expand file tree Collapse file tree 1 file changed +16
-0
lines changed
Specialized Areas/Regular Expressions/Consecutive duplicate words Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Original file line number Diff line number Diff line change 1+ // Consecutive Duplicate Words Detector
2+ // This regex finds repeated words that appear consecutively, such as "the the" or "and and".
3+ // Useful for grammar or text quality checks.
4+
5+ const duplicateWordsRegex = / \b ( [ A - Z a - z ] + ) \s + \1\b / gi;
6+
7+ function hasDuplicateWords ( text ) {
8+ return duplicateWordsRegex . test ( text ) ;
9+ }
10+
11+ // Example usage:
12+ console . log ( hasDuplicateWords ( "This is the the example." ) ) ; // true
13+ console . log ( hasDuplicateWords ( "We need to to check this." ) ) ; // true
14+ console . log ( hasDuplicateWords ( "Everything looks good here." ) ) ; // false
15+ console . log ( hasDuplicateWords ( "Hello hello world." ) ) ; // true (case-insensitive)
16+ console . log ( hasDuplicateWords ( "No repetition found." ) ) ; // false
You can’t perform that action at this time.
0 commit comments