How to describe string with only repeated characters groups in regular expression in Python
<p>i.e. <code>'aaeegggwwqqqqq', 'ttteeyyjjj'</code></p>

<p>I tried <code>r'(([a-z])\1*)+$'</code>, but get error said: cannot refer to open group.</p>

<p>Anyone can help me figure it out? Thanks!</p>

<p>Does</p>

<pre><code>(([a-z])\2*)+$
</code></pre>

<p>work?</p>

<p>Just quickly looking, <code>(([a-z])\2*)</code> is the first group and <code>([a-z])</code> is the second group. It looks like you meant to reference the second group.</p>

python regex