title: Python regex remove dots from dot separated letters
body: <p>I would like to remove the dots within a word, such that <code>a.b.c.d</code> becomes <code>abcd</code>, But under some conditions:</p>
  <ul>
  <li>There should be <em>at least 2 dots within</em> the word, For example, <code>a.b</code> remains <code>a.b</code>, But <code>a.b.c</code> is a match.</li>
  <li>This should match on 1 or 2 letters only. For example, <code>a.bb.c</code> is a match (because <code>a</code>, <code>bb</code> and <code>c</code> are 1 or 2 letters each), but <code>aaa.b.cc</code> is not a match (because <code>aaa</code> consists of 3 letters)</li>
  </ul>
  <p>Here is what I've tried so far:</p>
  <pre class="lang-py prettyprint-override"><code>import re
  texts = [
      'a.b.c', # Should be: 'abc'
      'ab.c.dd.ee', # Should be: 'abcddee'
      'a.b' # Should remain: 'a.b'
  ]
  for text in texts:
      text = re.sub(r'((\.)(?P&lt;word&gt;[a-zA-Z]{1,2})){2,}', r'\g&lt;word&gt;', text)
      print(text)
  </code></pre>
  <p>This selects &quot;any dot followed by 1 or 2 letters&quot;, which repeats 2 or more times. Selection works fine, but replacement with  group, causes only on last match and repetition is ignored.</p>
  <p>So, it prints:</p>
  <pre><code>ac
  abee
  a.b
  </code></pre>
  <p>Which is not what I want. I would appreciate any help, thanks.</p>