我正在尝试匹配最后一个单词并从上一行中删除。你知道吗
import re
# regex to select words with _-
line = re.compile('s/^(\w+(?:[-_]\d+)?)\n(?=.*\1\b)//gm;')
here_text = '''befall_fallen-fell
closing-round
Line - Eddying, dizzying, closing-round
laughter-laugh_laugh
Line - With soft and drunken laughter-laugh_laugh
laughter-laugh_laugh
befall_fallen-fell
Line - Veiling all that may befall_fallen-fell'''
输入
befall_fallen-fell
closing-round
Line - Eddying, dizzying, closing-round
laughter-laugh_laugh
Line - With soft and drunken laughter-laugh_laugh
laughter-laugh_laugh
befall_fallen-fell
Line - Veiling all that may befall_fallen-fell
输出-尝试
befall_fallen-fell
Line - Eddying, dizzying, closing-round
Line - With soft and drunken laughter-laugh_laugh
laughter-laugh_laugh
Line - Veiling all that may befall_fallen-fell
不知道怎么开始。你知道吗
以下PCRE正则表达式应起作用:
或者,在python中:
你可以在regex101或ideone上试试。你知道吗
请注意,上一行中最后一个单词被删除的行将不会再次匹配:
将被替换为
而不是
相关问题 更多 >
编程相关推荐