EasyRegex Logo
EasyRegex
Neu

Match Repetitions of the Same Length in Python

python

Regulärer Ausdruck

^(.+?)\1+$
Kopieren
Haben Sie Feedback?

Erklärung

This regex pattern captures a group of characters (represented by .+?) that repeats exactly n times (\1) followed by the same group of characters. The ^ and $ ensure that the pattern matches the entire string.

python

Beispielverwendung

import re

pattern = '^(.+?)\1+$'
string1 = 'abcabcabcabc'
string2 = '123123123'

match1 = re.match(pattern, string1)
match2 = re.match(pattern, string2)

print(match1)
print(match2)
Kopieren

Ähnliche Reguläre Ausdrücke