使用 Windows CMD findstr 匹配由一个或多个空格分隔的两个单词的行
Use Windows CMD findstr to match lines with two words separated by one or more spaces
对于文件sub.txt
callfoo() # no match
call_foo() # no match
call foo() # match
call foo() # match
命令
findstr call.*foo sub.txt
匹配所有行。如何匹配最后两行,其中“call”和“foo”由一个或多个空格分隔且没有其他字符?尝试使用
的正则表达式
findstr /R call\s.*foo sub.txt
不匹配。
findstr /RC:"call *foo" sub.txt
找到 call
后跟 space,然后是零个或多个 space,然后是 foo
。
使用 /c
开关对于将 space 作为字符而不是分隔符处理至关重要。
\s
不是残缺的 findstr
REGEX 的一部分。
对于文件sub.txt
callfoo() # no match
call_foo() # no match
call foo() # match
call foo() # match
命令
findstr call.*foo sub.txt
匹配所有行。如何匹配最后两行,其中“call”和“foo”由一个或多个空格分隔且没有其他字符?尝试使用
的正则表达式findstr /R call\s.*foo sub.txt
不匹配。
findstr /RC:"call *foo" sub.txt
找到 call
后跟 space,然后是零个或多个 space,然后是 foo
。
使用 /c
开关对于将 space 作为字符而不是分隔符处理至关重要。
\s
不是残缺的 findstr
REGEX 的一部分。