Splitting strings in python using import re
<p>Why does this work:</p>

<pre><code>string = 'N{P}[ST]{P}'

&gt;&gt;&gt; import re
&gt;&gt;&gt; re.split(r"[\[\]]",  string)
&gt;&gt;&gt; ['N{P}', 'ST', '{P}']
</code></pre>

<p>But this don't?</p>

<pre><code>&gt;&gt;&gt; re.split(r"{\{\}}", string)
</code></pre>

<p>You have to do this:</p>

<pre><code>re.split(r"[{}]", string)
</code></pre>

<p><code>r"{\{\}}"</code> is a special re syntax to repeat groups (ex: <code>(ab){1,3}</code> matches <code>ab</code>, <code>abab</code> or <code>ababab</code>) but not the character range (note that you don't have to escape the curly braces in a character range).
(I admit I don't know what your strange regex is supposed to do specially in the re.split context, but not what you want :))</p>

python regex