我正在解析txt文件(共有+100页长),我想提取字符串“public offering price”第一次出现的句子。另外,我想清除句子中的“ ”字符。在
我在一系列文件(文件列表)上运行以下代码:test1 = [] #create a new list to store my desired output
for eachfile in file_list:
with open(eachfile, 'r') as f:
for line in f:
if "public offering price" in line:
test1.append(line.replace(' ','').split('.')[0])
print(test1)
通过上面的代码,我成功地清除了" "字符,并在“.”出现时拆分元素(这对我想要的输出有帮助),但是获得了以下输出:
^{pr2}$
上面的输出给出了所有的句子,包括我想要的字符串,但是我只想保留第一个出现的句子:['public offering price will be between $and $per share]
你知道如何获得这样的产出吗?鉴于我运行的代码,它一定很容易实现,但却不知道如何。。。在
提前非常感谢你
编辑:在不替换或拆分('.')[0]的情况下获得的输出如下:['public offering price will be between $ and $ per share. We intend to apply to list the common stock on\n', 'to additional shares of our common stock at the initial public offering price.\n', '(2) an initial public offering price of $ per share, the midpoint of the initial public offering range indicated on the cover of this prospectus. \n']