【发布时间】:2021-11-06 06:17:48
【问题描述】:
text = "A random\string here"
test = re.findall('(?<=A ).+\s', text)
我只想打印从“A”结尾(不包括空格)到字符串结尾的所有内容。
我只想得到“随机\字符串”
【问题讨论】:
-
把预期的输出,为什么你用“这个”?
-
1) 不要使用
str作为变量名,它是内置的,2)re.findall(r'A\s+(.+)', text)或re.findall(r'^A\s+(.+)', text) -
我试过
re.findall(r'^A\s+(.+)', text)但这不起作用,因为在这种情况下它也会打印“这里”这个词