Powershell - notMatch

NiC*_*iCU 6 regex powershell

我想从文件中选择与特定模式不匹配的所有行; 我知道我必须使用select-string的-notMatch选项,但我无法弄清楚如何.(我正在寻找类似GREP的-v函数)任何例子都会很有用.提前致谢.

Dam*_*ell 5

我想你还是想要match而不是notmatch。要排除函数返回类型或注释,您需要“否定断言”。也许这会满足您的要求?

$f = 'my_function'
select-string test.txt -Pattern "(?<!(void|double|char|int)\s+|//.*)\b$f\b"
Run Code Online (Sandbox Code Playgroud)

(?<!...)部分表示如果在源文本中此时找到“...”,则不匹配。


ond*_*vic 5

你不能使用以下内容

-notmatch "(?<!(void|double|char|int)\s+|//.*)\b$f\b"
Run Code Online (Sandbox Code Playgroud)