正则表达式 - 排除带有单词 (php) 的行

请帮忙,如果其中存在某个单词,如何排除字符串的存在。

例子:

any text here my text any text word wrong any text
any text here my text any text true any text
any text here my text any text wrong any text

此正则表达式标记所有行 ( https://regex101.com/r/rrgEp6/1 ):

here([a-z, ]{0,70})((?:(?! word))) (wrong|true)

在这种情况下需要排除单词 - “单词”:

any text here my text any text true any text
any text here my text any text wrong any text


侃侃无极
浏览 167回答 2
2回答

墨色风雨

你可以使用here((?:(?!\bword\b)[a-z ,]){0,70}) (wrong|true)请参阅正则表达式演示细节here- 一个字符串((?:(?!\bword\b)[a-z ,]){0,70})- 第 1 组:小写字母、空格或逗号,出现 0 到 70 次,不word以整个单词字符序列开头 - 空间(wrong|true)- 第 2 组:wrong或true字符序列。

蝴蝶刀刀

您可以使用^(?!.*\bword\b).+请参阅regex101.com 上的演示。
打开App,查看更多内容
随时随地看视频慕课网APP