Python regex find all substrings between two character pairs
<p>I have tried previous answers here on SO. I was able to find only one subset of several. </p>

<p>here is the code and sample that I am working on.</p>

<pre><code>s = "{| mySting0 |}  The {| mySting1 |}  The {| mySting2 |}  The {| mySting3 |}  make it work "

result = re.findall('{\|(.*)|}', s)
</code></pre>

<p>the output is,</p>

<pre><code>[' mySting0 |}  The {| mySting1 |}  The {| mySting2 |}  The {| mySting3 |}  make it work ']
</code></pre>

<p>What am I doing wrong?</p>

<p>You can use this regex:</p>

<pre><code>&gt;&gt;&gt; s = "{| mySting0 |}  The {| mySting1 |}  The {| mySting2 |}  The {| mySting3 |}  make it work "
&gt;&gt;&gt; re.findall(r'{\|(.*?)\|}', s)
[' mySting0 ', ' mySting1 ', ' mySting2 ', ' mySting3 ']
</code></pre>

<p><strong>Changes are:</strong></p>

<ol>
<li>Use lazy quantifier <code>.*?</code> instead of greedy <code>.*</code></li>
<li>Excape 2nd <code>|</code> as well in your regex</li>
</ol>

python regex