Need to cut out all characters in between 2 brackets in a string
<p>I have a string in python 2.7:</p>

<pre><code>a = 'This is some text ( - 1) - And some more text (0:0) - Some more Text'
</code></pre>

<p>I would like to use a regex to get the ' - 1' out of this string. </p>

<p>I've tried but can't find it, thanks for your help, I've tried: </p>

<pre><code>re.search(r'.*?\((.*)\).*', a)
</code></pre>

<p>But that didn't work. Mind you there's a second ( ) in the string but I only need the first one. </p>

<p>THANK YOU!</p>

<p>regexes are greedy by default. Your expression gets the first <code>(</code> to the last <code>)</code></p>

<p>you did that:</p>

<pre><code>re.search(r'.*?\((.*)\).*', a)
</code></pre>

<p>instead, use</p>

<pre><code>re.search(r'.*?\((.*?)\).*', a)
</code></pre>

<p>note the non-greedy version of the match <code>.*?</code> (I just added a question mark to your regex to make it work)</p>

<p>Variant: avoid closing parenthesis in your group capture</p>

<pre><code>re.search(r'.*?\(([^)]*)\).*', a)
</code></pre>

python regex