This expression will match one or more repeating groups:
(.+)(?=\1+)
Here is the same expression broken down, (using commenting so it can still be used directly as a regex).
(?x) # enable regex comment mode
( # start capturing group
.+ # one or more of any character (excludes newlines by default)
) # end capturing group
(?= # begin lookahead
\1+ # match one or more of the first capturing group
) # end lookahead
To match a specific pattern, change the .+
to that pattern, e.g. \d+ for one or more numbers, or \d{4,}
to match 4 or more numbers.
To match a specific number of the pattern, change \1+
, e.g to \1{4}
for four repetitions.
To allow the repetition to not be next to each other, you can add .*?
inside the lookahead.