How to extract number from text in python?
<p>I have the string listed below</p>

<pre><code>str = ['"Consumers_Of_Product": {"count": 13115}']
</code></pre>

<p>How can I extract the number 13115 as it will change, so that it will always equal var. In other words how do I extract this number from this string?</p>

<p>Most things I've done previously have not worked and I think that is due to the syntax. I'm running Python 2.7.</p>

<p>If you just want to extract that number, provided there are no other numbers in that string, you can use <code>regex</code>. I renamed <code>str</code> to be <code>s</code> for the reason mentioned in @TigerhawkT3 answer.</p>

<pre><code>import re
s = ['"Consumers_Of_Product": {"count": 13115}']
num = re.findall('\d+', s[0])
print(num[0])
13115
</code></pre>

python string python-2.7 integer