当前位置: 动力学知识库 > 问答 > 编程问答 >

regex expression or in batch

问题描述:

How can I write a regex expression with OR in batch.

I have a file and I want to find "aa" or "bb".

The file contains these lines:

aa

bb

cc

This is the command I have tryed:

findstr /I /R /C:"aa\|bb" temp.txt

and

findstr /I /R /C:"aa|bb" temp.txt

Can anyone help me with the OR syntax in batch for writing regular expressions.

Thanks.

网友答案:

Quoted from the doc:

FINDSTR does not support alternation with the pipe character (|) multiple Regular Expressions can be separated with spaces, just the same as separating multiple words (assuming you have not specified a literal search with /C) but this may not be useful if the regex itself contains spaces.

Reference: http://ss64.com/nt/findstr.html

网友答案:

The default behaviour of findstr is to include all lines that match at least one of the conditions. So, your findstr line should be

findstr /i /c:"aa" /c:"bb" temp.txt
分享给朋友:
您可能感兴趣的文章:
随机阅读: