in reply to Finding repeat sequences.
The easiest way to do it with is regex is to use the reversed string, because if you want to check that the end is included in the repeated pattern, you have to be able to make a reference to it.
$_ = reverse 'abcdabcdabceabcdabcdabceab'; /^(.*)(.+?\1)\2*$/; print scalar reverse $2;
abcdabcdabce
Edit: it probably is faster with the pattern /^(.+?)(.*?\1)\2*$/ since it uses a minimum length string as the trailing partial repetition, instead of a maximum one (ie : it does not read the whole input and bactracks). The first one should work in any case though, the second would work only if the base string is repeated at least once, even partially.
|
|---|