我有一个看起来像这样的文件:在每一行提取文本文件
Breve, a writ; used more frequently in the plural brevia.
Brevia magistralia, official writs framed by the clerks in
chancery to meet new injuries, to which the old forms of action
were inapplicable. Sea Trespass on the case. Brevia testata,
short attested memoranda, originally introduced to obviate the
uncertainty arisina; from parol feoffments, hence modern con-
veyances have gradually arisen.
我想提取第一个逗号之前出现的词(,)
预期输出:
Breve
Brevia magistralia
chancery to meet new injuries
were inapplicable. Sea Trespass on the case. Brevia testata
short attested memoranda
uncertainty arisina; from parol feoffments
我的代码:
with open('test.txt','r') as file:
for line in file:
print(line[0:line.find(',')])
输出:
Breve
任何帮助表示赞赏
'+' 演示?(= [^。] + \?):https://regex101.com/r/ YhNuVd/2 – Gurman
我得到更长的输出。 – Goyo
决定一个答案是否有帮助,然后你可以接受最好的答案:https://stackoverflow.com/help/someone-answers –