Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/337.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Python中使用正则表达式将混乱的字符串拆分为字母和数字_Python_Regex_Pandas - Fatal编程技术网

如何在Python中使用正则表达式将混乱的字符串拆分为字母和数字

如何在Python中使用正则表达式将混乱的字符串拆分为字母和数字,python,regex,pandas,Python,Regex,Pandas,我有两条线: x ='plasma_glucose_concentration183.0000' y = 'Participants20-30' 并希望按如下方式拆分字符串: x: ['plasma_glucose_concentration', '183.0000'] y: ['Participants, 20-30'] 我创建了此函数,但只正确拆分了第一个字符串: def split_string(x): res = re.findall(r"(\w+?)(\d*\.

我有两条线:

x ='plasma_glucose_concentration183.0000'
y = 'Participants20-30'
并希望按如下方式拆分字符串:

x: ['plasma_glucose_concentration', '183.0000']
y: ['Participants, 20-30']

我创建了此函数,但只正确拆分了第一个字符串:

def split_string(x):
    res = re.findall(r"(\w+?)(\d*\.\d+|\d+)", x)
    return res
当我拆分第二个字符串时,我得到:

  [('Participants', '20'), ('3', '0')]

有什么正则表达式解决方案吗?Thx.

您可以使用

重新导入
x=[‘血浆葡萄糖浓度183.0000’,‘参与者20-30’,‘2小时血清胰岛素543.0000’]
对于x中的s:

print(re.split(r')(?谢谢,如果字符串如下:
'2小时血清胰岛素543.0000'
?@madmax80没问题。实际上,我想得到
['2小时血清胰岛素','543.0000']
,而不是
['2','2小时血清胰岛素','543.0000']
@madmax80好的,请参阅更新。谢谢,我更改了Python版本,现在可以使用了。