【发布时间】:2020-09-18 12:05:16
【问题描述】:
我有以下格式的字符串:(带有 3 个或更多空格的句子和这些句子之间的句子是表格数据的一部分)
Some Sentence
Some sentence
Balance at January 1, $421 $51
Additions based on tax positions related to the
current year 4 34 9
Additions based on acquisitions - - 2
Additions based on tax positions related to prior
years 21 13 374
Reductions for tax positions of prior years (54) (43) -
Some paragraph
Some paragraph
Balance at January 1, $421 $51
Additions based on tax positions related to the
current year 4 34 9
Additions based on acquisitions - - 2
Additions based on tax positions related to prior
years 21 13 374
Reductions for tax positions of prior years (54) (43) -
我需要从包含 3 个或更多空格的字符串中删除所有句子,记住应该保留实际的段落内容。
以下是我的方法,它没有给我准确的结果,我也不喜欢使用 range(5):
for i in range(5):
result = re.sub('[\\n-].* {3,}.*\\n', '', result)
print(result)
我的逻辑输出:
Some Sentence
Some sentence
Additions based on tax positions related to the
Additions based on tax positions related to prior
Some paragraph
Some paragraph
Additions based on tax positions related to the
Additions based on tax positions related to prior
预期输出:
Some Sentence
Some sentence
Some paragraph
Some paragraph
还有什么办法让句子之间的句子(有 3 个或更多空格)也被删除?
【问题讨论】:
标签: python python-3.x