http://www.perlmonks.org?node_id=1039665


in reply to Re^4: Finding repeat sequences. (only regex)
in thread Finding repeat sequences.

I think I had \1 and \2 backward. Then you just have to disallow the trivial solution:

$s = 'aaaabaaaabaaaaabaaaab'; $s =~ /^((.*?).*?)(?=.)\1*\2$/ and print "$2/$1";

(Update: Dropped the unneeded () around \1 that I had introduced while debugging. You probably also need to change .*? to .* so you get the longest solution not the shortest.)

- tye