how to take exact matched phrases using regular expression when multiple braces are present
<p>I have texts like</p>

<pre><code>1) &lt;img="" id=""&gt;data&lt;/img&gt;
2) (hi "hello") data (some text)
</code></pre>

<p>I want to remove only the text with braces and angular brackets and extract in between data. I tried</p>

<pre><code>re.compile(r"\(.*\)")
re.compile(r"&lt;.*&gt;")
</code></pre>

<p>but since closing braces are at the end of text, whole text is getting deleted when re.sub is used.
How to take the only data in between multiple braces (angular or flower brackets)</p>

<pre><code>In [68]: re.sub(r'&lt;(.+?)&gt;', '', '&lt;img="" id=""&gt;data&lt;/img&gt;')
Out[68]: 'data'
</code></pre>

<p>Regex explanation:</p>

<pre><code>&lt;(.+?)&gt;
</code></pre>

<p><img src="https://www.debuggex.com/i/dRCzoEj0k9pnANPt.png" alt="Regular expression visualization"></p>

<p><a href="https://www.debuggex.com/r/dRCzoEj0k9pnANPt" rel="nofollow">Debuggex Demo</a></p>

<pre><code>In [68]: re.sub(r'\((.+?)\)', '', '(hi "hello") data (some text)')
Out[68]: ' data '
</code></pre>

<p>Regex explanation:    </p>

<pre><code>\((.+?)\)
</code></pre>

<p><img src="https://www.debuggex.com/i/9YhgsadiKl-9cXc-.png" alt="Regular expression visualization"></p>

<p><a href="https://www.debuggex.com/r/9YhgsadiKl-9cXc-" rel="nofollow">Debuggex Demo</a></p>

<p>Read the section 'Watch Out for The Greediness!' at <a href="http://www.regular-expressions.info/repeat.html" rel="nofollow">http://www.regular-expressions.info/repeat.html</a></p>

python regex text-processing