问题描述:

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
相关阅读:
Top