title: Check if string is repetition of an unknown substring
body: <p>I'm trying to write a regex or Ruby method which will find the longest repeated pattern in a string. For example:</p>
  
  <pre><code>"abcabc"  =&gt; "abc"  
  "cccc" =&gt; "c"
  "abcd" =&gt; "abcd"
  </code></pre>
  
  <p>What is the best way to implement this? I naïvely tried <code>/^(.*)*$/</code> but that won't work as it just matches the full string.</p>