in reply to Re^2: Finding repeat sequences.
in thread Finding repeat sequences.
DB<127> $str => "abcdabcdabceabcdabcdabceab" DB<128> $str=~/^((.+?).*)\2$/; $rest=$1, $tail=$2 => ("abcdabcdabceabcdabcdabce", "ab") DB<129> $rest =~ /^(.+?)\1*$/; $1 => "abcdabcdabce"
needs to be extended for longer possible tails.
But taking the dimensions of your data I doubt that regexes are appropriate.
You could test all $patterns which repeat at least once (or x times) and calculate $k = $m % $l with $m =length ($str), and check if $str starts and ends with the same substring $tail of length $k and then check if the pattern continues repeating.
Or start eliminating all possible $tails and check if $l of a repeating pattern is a divisor of the $rest.
Had no time to check all the other posted solutions and don't wanna reinvent the wheel, so I better stop here! =)
HTH
Cheers Rolf
( addicted to the Perl Programming Language)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Finding repeat sequences.
by BrowserUk (Patriarch) on Jun 21, 2013 at 02:48 UTC |