Method 1:
Without regular expressions (regexes), one can simply use sets. First, split the string s in question into substrings of the same length as the substring substr. Make a set s_set out of these substrings. If that set has only 1 element, and that element in substr, then print True, otherwise False.
strs = ["WorldWorldWorld", "Hello World"]
substr = "World"
len_substr = len(substr)
for s in strs:
s_set = set(s[i:(i + len_substr)] for i in range(0, len(s), len_substr))
print(len(s_set) == 1 and substr in s_set)
# True
# False
Method 2:
If speed is important, then for very long strings, it makes sense to stop as soon as the first non-matching substring is found, as in this solution:
for s in strs:
only_substr = True
for i in range(0, len(s), len_substr):
cur_substr = s[i:(i + len_substr)]
if cur_substr != substr:
only_substr = False
break
print(only_substr)
# True
# False