title: A regex to detect periodic strings
body: <blockquote>
    <p>A period <code>p</code> of a string <code>w</code> is any positive integer <code>p</code> such that <code>w[i]=w[i+p]</code>
    whenever both sides of this equation are defined. Let <code>per(w)</code> denote
    the size of the smallest period of <code>w</code> . We say that a string <code>w</code> is
    periodic iff <code>per(w) &lt;= |w|/2</code>.  </p>
  </blockquote>
  
  <p>So informally a periodic string is just a string that is made up from a prefix repeated at least twice.  The only complication is that at the end of the string we don't require a full copy of the prefix.</p>
  
  <p>For, example consider the string <code>x = abcab</code>. <code>per(abcab) = 3</code> as <code>x[1] = x[1+3] = a</code>, <code>x[2]=x[2+3] = b</code> and there is no smaller period. The string <code>abcab</code> is therefore not periodic.  However, the string <code>ababa</code> is periodic as <code>per(ababa) = 2</code>.</p>
  
  <p>As more examples, <code>abcabca</code>, <code>ababababa</code> and <code>abcabcabc</code> are also periodic.</p>
  
  <blockquote>
    <p>Is there a regex to determine if a string is periodic or not?</p>
  </blockquote>
  
  <p>I don't really mind which flavor of regex but if it makes a difference, anything that Python <code>re</code> supports.</p>