【发布时间】:2020-08-08 09:28:03
【问题描述】:
我正在尝试获取两个“|”之间的子字符串(空格、“.”和 1)。
我尝试了以下代码:
f = open('test.txt', 'r')
with f:
data = f.read()
for line in data.splitlines():
if line.startswith('Y='):
m = re.search('| (.+?) |', line)
if m:
found = m.group(1)
print(found)
但唯一打印出来的是“无”。
test.txt 中的文本:
【问题讨论】:
标签: python regex python-3.x python-2.7