擅长:python、mysql、java
<pre><code>import re
def substring(string):
output = {}
name = string.split()[0]
for i in range(1,len(string.split())):
if len(re.findall('\d', string.split()[i]))==0:
name = name + " " + string.split()[i]
else:
quantity = " ".join(string.split()[i:])
break
output["Name"] = name
output["Quantity"] = quantity
return output
</code></pre>
<p>然后将字符串放入该函数中,如下所示:</p>
^{pr2}$
<p>你将得到:</p>
<p>{'Name':'新鲜值生木瓜','数量':'1U(单位)(300g-400g)}</p>