簡體   English   中英

正則表達式 - 排除帶有單詞的行(php)

[英]regex - Exclude the line with the word (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

您可以使用

^(?!.*\bword\b).+

請參閱regex101.com 上的演示

您可以使用

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

查看正則表達式演示

細節

  • here - 一個字符串
  • ((?:(?,\bword\b)[az,]){0,70}) - 第 1 組:小寫字母、空格或逗號,出現 0 到 70 次,不以整個word開頭字符序列
  • - 空間
  • (wrong|true) - 第 2 組: wrongtrue字符序列。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM