记事本++中的通配符搜索以获取特定行,如果它匹配第一次和最后一次搜索之间的任何字符串,但空格除外

wildcard search in notepad++ to get particular line if it matches any string between first and last search except whitespaces

  1. this is sample text jfhwkjefwl todo
  2. here sample text todo
  3. sample text todo

我只想select第一个语句"this is sample text jfhwkjefwl todo"。我尝试了 [t][e][x][t].*[t][o][d][o][t][e][x][t ].*[t][o][d][o].

的不同组合

谁能帮助我将不胜感激。

你的意思是这样的吗?

.*text\s+\S+\s+todo.*

表示任何可选 (.*) 后跟“文本”后跟至少一个空格 (\s+) 后跟至少一个非空格 (\S+) 后跟至少一个空格后跟“todo”。 因此,如果您想匹配整行,那么您的正则表达式必须匹配您想要的所有内容,而不仅仅是一个子字符串。

我建议采用与 类似的方法,但有一点不同:懒惰捕获而不是贪婪:

text\s+\S+?\s+todo    # non greeedy search, until first todo

而不是

text\s+\S+\s+todo # greeedy search, until last todo

延迟捕获匹配直到第一行 todo - 而不是最后一行。在 notepad++ 中,非贪婪搜索(参见第二个匹配项)如下所示: