首页 > 解决方案 > Python Regex:Findall从字符串的开头到结尾匹配字符串

问题描述


text = "A random\string here"
test = re.findall('(?<=A ).+\s', text)

我只想打印从“A”结尾(不包括空格)到字符串结尾的所有内容。

我只想得到“随机\字符串”

标签: pythonregexfindall

解决方案


如果您想要简单的东西,我建议使用 split 而不是正则表达式(类似于 ‍‍<code>test=text.split('A')[1])

如果你真的想使用正则表达式,你可以使用这种网站来调试它:https ://regex101.com/


推荐阅读