regex - Regular Expression find same word repeatead on a line -


i try create regex find word can appear example 3 times on line. example have "my cat here , second cat , third cat there."

so create regex :

^(\b\w{3,}\b).*\1 

it works 2 times appearing. if add want more 3 times :

^(\b\w{3,}\b).*\1{3,} 

it doesn't work. try find word @ least 3 letters long , can appear @ least 3 times on same line.

someone have idea ?

thanks

your regex must be,

(\b\w{3,}\b).*\1.*\1 

\1{3,} search 3 or more times of captured word

or

(\b\w{3,}\b)(?:.*\1){2,} 

.* matches character, 0 or more times. \1 refers chars present inside first capturing group. (?:.*\1){2,} search captured string appear more twice. if yes, matching. 3 or more, change number 2 present inside repeatation quantifier 3. {2,} repeats previous token (?:.*\1) 2 or more times.


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -