Regex - match any sequence that repeats n times


Do you know how to fit a group that repeats n times? eg:.

That is, is is test   [incl. the spaces between two 'is']
the F oo bar
T Elel : +49 1 88 /123 45 45 45

I tried the following regex pattern: (\w+)\1+
but it matches only two occurrences of the group (not n entries)

Many thanks

+4
source share
1 answer

The problem with your template regarding your sample input is that the template does not take into account possible trailing spaces:

(\w+\s*)\1+

Demo version

, : , "ba ba ba ba b" "a ba ba ba ba b", " a ba ba ba ba b".

+4

All Articles