擅长:python、mysql、java
<p>您可以使用更通用的正则表达式来替换除以下字符以外的所有特殊字符。你知道吗</p>
<pre><code>import re
def text_process(text):
text = re.sub('[^\w.]+', ' ', text)
return text
s = 'Transaction: value* #was - 3456.63 Rupees'
text_process(s)
</code></pre>
<p>你得到了吗</p>
<pre><code>'Transaction value was 3456.63 Rupees'
</code></pre>
<p>EDIT:下面的函数只返回带小数的数字。你知道吗</p>
<pre><code>def text_process(text):
text = re.sub('[^\d.]+', '', text)
return text
s = 'Transaction: value* #was - 3456.63 Rupees'
text_process(s)
'3456.63'
</code></pre>