findstr找不到"现在"

时间:2017-05-12 08:39:24

标签: batch-file findstr

我没有很多 findstr 的经验,但这对我来说根本不可理解。或者它是findstr的错误吗?

看看这些例子:

1)echo NOW|findstr "CLEAN NOCHANGE NOW">NUL&&echo found 什么也不回来但是为什么?

2)echo CLEAN|findstr "CLEAN NOCHANGE NOW">NUL&&echo found 返回在这里发现它没关系

3)echo NOCHANGE|findstr "CLEAN NOCHANGE NOW">NUL&&echo found 返回发现这也有效

但是,当我使用/ I时,它会起作用 4)echo NOW|findstr /I "CLEAN NOCHANGE NOW">NUL&&echo found - >返回发现它确定

如果'现在'是小写 - >它的工作原理 5)echo now|findstr "CLEAN NOCHANGE now">NUL&&echo找到了 - >返回发现

是否有特别的字符串" NOW" ?

1 个答案:

答案 0 :(得分:0)

根据线程Why doesn't this FINDSTR example with multiple literal search strings find a match?findstr在具有多个文字区分大小写的搜索字符串时行为不正确,这些搜索字符串长度不同且部分重叠。另请参阅此帖子:What are the undocumented features and limitations of the Windows FINDSTR command?

以下是使用正则表达式搜索字符串的解决方法,因为没有使用元字符:

echo NOW| findstr /R "CLEAN NOCHANGE NOW" > nul && echo found

以下是针对每个文字搜索字符串使用单独findstr命令的解决方法:

echo NOW| (findstr /V "CLEAN" | findstr /V "NOCHANGE" | findstr /V "NOW") > nul || echo found

这是基于findstr的小兄弟的另一种解决方法,即find命令:

echo NOW| (find /V "CLEAN" | find /V "NOCHANGE" | find /V "NOW") > nul || echo found