在本文中:
warning here there are several types of warnings in this string warning.gif at the end warning end of line warning
我想匹配除warning
以外的每个warning.gif
。
我似乎无法将它包括在其后没有字符(控制或其他)的最后一个。
使用warnings?[^\.]
获取我想要的内容,除了最后一个警告(在最后一行)。我想因为之后没有任何角色。我怎样才能把它包含在那个?
答案 0 :(得分:4)
如果你有负面的前瞻,你可以使用它:
/warnings?(?!\.gif)/
这应该适用于Javascript。
答案 1 :(得分:1)
我完全误解了这个问题。道歉。
以下是更正后的解决方案:
替代品可以比eof标记更紧密地绑定。
示例文件:
warning here
there are several types of warnings
in this string warning.gif
at the end warning
end of line warning
示例脚本:
awk '/warnings?$|warnings?[[:space:]]/ { print }' /home/geocar/g.txt
原文(错误)答案:
使用:/warnings?$/m
- 请注意“?”表示“s”是可选的