Community Patterns

Community Library Entry

2

Regular Expression
Created·2024-10-08 14:00
Flavor·PCRE2 (PHP)

/
(?=(\b\w{4,}\b)(?:.*\b\1\b){2})(?!(\b\w{4,}\b)(?:.*\b\1\b){3})
/
gi
Open regex in editor

Description

I'd like to know if a text contains words with 4 characters or more which are repeated 3 or more times in the text (anywhere in the text).

If so, set one (and only one) backreference for each word.

Submitted by anonymous