regex - Backreferencing something without putting it in the rest of the expression -
i trying create regular look match words have letter repeats @ to the lowest degree arbitrary number of times.
for example, if want match words have letter repeats @ to the lowest degree 3 times, want match words like
applepie banana insidious
i want able alter number of repeats i'm looking changing 1 number in expression, expressions work number of repeats not i'm looking for.
currently, i'm using
^(?=.*(.))(?=(.*\1){4}).*$
where 4 number of repeats, number can alter whatever number of repeats i'm looking for.
the above regular look appears work, using lookahead can utilize capturing grouping seems unwieldy, , i'm looking improve way solve problem.
this eliminate 1 lookahead:
\b(?=\w*(\w)(\w*\1){2})\w*
start of word, number of word-characters such consist of number of word characters, particular word character, , number of characters , character again, repeated @ to the lowest degree twice.
for 4 repetitions, utilize {3}
(for n
repetitions, utilize 1 less).
also, sense free replace \b...
^...$
doing if meant match whole lines , not words in text.
regex pcre
No comments:
Post a Comment