擅长:python、mysql、java
<p>你也可以试试这个:</p>
<pre><code>def split_unit(stri):
to_split = re.findall("\\d+",stri)[0]
splitted = to_split + stri.split(to_split,1)[1]
print(splitted)
split_unit("Fresh Value Colocasia 250g") #outputs : 250 g
split_unit("Fresh Value Banana Robusta 1kg") #outputs : 1Kg
split_unit("Fresh Value Raw Papaya 1 U (units) (300g-400g)") # outputs:1 U
#(units) (300g-400g)
</code></pre>
<p>以此类推,我所做的是,首先在函数内部的第一行使用regex,找到字符串中第一个出现的intiger。和使用结构分裂()方法拆分第一个整数后的所有字符,并将其与第一个整数的to_split合并。在</p>