inp = ['43.990\none of the things we notice\nis that the headers all have\n\n296\n', '47.020\nthe word edit and\nbraces behind them,\n\n297\n']
output = [re.sub(r'\s*\d+(?:\.\d+)?\s*', ' ', x).strip() for x in inp]
print(output)
这张照片是:
['one of the things we notice\nis that the headers all have',
'the word edit and\nbraces behind them,']
我将使用:
这张照片是:
您可以使用
re.sub
替换与正则表达式匹配的字符,并在行的开头和结尾加上锚:输出(对于两个样本数据):
注意:我假设数据中的
\n
是一个实际的换行符,如果不是(它是文字字符串\n
),则应该使用以下内容:输出:
相关问题 更多 >
编程相关推荐