.*?any character (except for line terminators), repeated any number of times
Comment: if we already have captured the end of the string
Condition(?(1)
# make sure we do not go past the correct position
(?= .\1$ )
) Uses the first branch if group 1 matched
If the condition is true, match this branch:
# make sure we do not go past the correct position
(?= .\1$ )
Comment: make sure we do not go past the correct position
Positive Lookahead(?= .\1$ ) .any character (except for line terminators)
\1the text saved by group 1
$end of line
Comment: capture the end of the string +1 character, adding to \1 every iteration
.any character (except for line terminators)
\1?optionally matches the text saved by group 1
$end of line