Python - Convert string-numeric to float
<p>I have the following string numeric values, and need to keep only the digit and decimals. I just can't find a right regular expression for this. </p>

<pre><code>s = [
      "12.45-280", # need to convert to 12.45280
      "A10.4B2", # need to convert to 10.42
]
</code></pre>

<p>You can also remove all non-digits and non-dot characters, then convert the result to float:</p>

<pre><code>In [1]: import re
In [2]: s = [
   ...:       "12.45-280", # need to convert to 12.45280
   ...:       "A10.4B2", # need to convert to 10.42
   ...: ]

In [3]: for item in s:
   ...:     print(float(re.sub(r"[^0-9.]", "", item)))
   ...:     
12.4528
10.42
</code></pre>

<p>Here <code>[^0-9.]</code> would match any character except a digit or a literal dot. </p>

python regex typeconverter