Changing strings into integers
<p>I'm going crazy and I can not figure the right solution :(</p>

<p>How can I solve that problems. I have a loop and I can get diffrent types like:</p>

<pre><code>empty string
10
10K
2.3K
2.34K
2M
2.2M
2.23M
</code></pre>

<p>I need to change them into numbers:</p>

<pre><code>0
10
10000
2300
2340
2000000
2200000
2230000
</code></pre>

<p>I agree with other answers, this solution will be best to solve it without Regular Expression.</p>

<p>But, if you still want to use regex, here is a nice way to do this using JavaScript (sorry, not familiar with Python):</p>

<pre><code>var new_arr = ['','10','10K','2.3K','2.34K','2M','2.2M','2.23M'].map(function(value) {
    return value.replace(/^(\d*(?:\.\d+)?)([kgm]?)$/i, function(_, number, group) {
        return !group &amp;&amp; (number||'0') || parseFloat(number) * Math.pow(10, {'k':3,'m':6,'g':9}[group.toLowerCase()]);
    });
});
</code></pre>

<p>If someone could translate it to Python, it would be best (and it will teach me a bit of Python well). :))</p>

python regex python-2.7