title: A python regex that matches the regional indicator character class
body: <p>I am using python 2.7.10 on a Mac.
  Flags in emoji are indicated by a pair of <a href="https://en.wikipedia.org/wiki/Regional_Indicator_Symbol" rel="nofollow noreferrer"><strong>Regional Indicator Symbols</strong></a>. I would like to write a python regex to insert spaces between a string of emoji flags.</p>
  <ul>
  <li><p>For example, this string is two Brazilian flags:</p>
  <ul>
  <li><p><code>u&quot;\U0001F1E7\U0001F1F7\U0001F1E7\U0001F1F7&quot;</code></p>
  </li>
  <li><p>which will render like this: </p>
  </li>
  </ul>
  </li>
  </ul>
  <p>I'd like to insert spaces between any pair of regional indicator symbols.  Something like this:</p>
  <pre><code>re.sub(re.compile(u&quot;([\U0001F1E6-\U0001F1FF][\U0001F1E6-\U0001F1FF])&quot;),
         r&quot;\1 &quot;, 
         u&quot;\U0001F1E7\U0001F1F7\U0001F1E7\U0001F1F7&quot;)
  </code></pre>
  <p>...which would result in:</p>
  <pre><code>u&quot;\U0001F1E7\U0001F1F7 \U0001F1E7\U0001F1F7 &quot;
  </code></pre>
  <p>...but that code gives me an error:</p>
  <pre><code>sre_constants.error: bad character range
  </code></pre>
  <p>A hint (I think) at what's going wrong is the following, which shows that \U0001F1E7 is turning into two &quot;characters&quot; in the regex:</p>
  <pre><code>re.search(re.compile(u&quot;([\U0001F1E7])&quot;),
            u&quot;\U0001F1E7\U0001F1F7\U0001F1E7\U0001F1F7&quot;).group(0)
  </code></pre>
  <p>This results in:</p>
  <pre><code>u'\ud83c'
  </code></pre>
  <p>Sadly my understanding of unicode is too weak for me to make further progress.</p>