Repeated Words Regex

Detects consecutive duplicate words in text.

パターン

/\b(\w+)\s+\1\b/gi
→ ビジュアライザーで開く

テスト例

This is is a test. The the quick brown fox fox jumped.

コード例

javascript

const regex = /\b(\w+)\s+\1\b/gi;
const result = str.match(regex);

python

import re
pattern = re.compile(r'\b(\w+)\s+\1\b', re.IGNORECASE)
result = pattern.findall(text)

go

import "regexp"
re := regexp.MustCompile(`(?i)\b(\w+)\s+\1\b`)
result := re.FindAllString(text, -1)
textduplicateediting