Extract values between square brackets ignoring single quotes
<p>I am trying the following:</p>

<pre><code>s = "Text text text [123] ['text']"
</code></pre>

<p>This is my function:</p>

<pre><code>def getFromSquareBrackets(s):
    m = re.findall(r"\[([A-Za-z0-9_']+)\]", s)
    return m
</code></pre>

<p>But I am obtaining:</p>

<pre><code>['123', "'text'"]
</code></pre>

<p>I want to obtain:</p>

<pre><code>['123', 'text'] 
</code></pre>

<p>How can I ignore the single quotes?</p>

<p>Make <code>'</code> optional and outside the capturing group</p>

<pre><code>m = re.findall(r"\['?([A-Za-z0-9_]+)'?\]", s)
</code></pre>

python regex