Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex 如何查找包含两个字符串的所有文件?_Regex_Batch File_Findstr - Fatal编程技术网

Regex 如何查找包含两个字符串的所有文件?

Regex 如何查找包含两个字符串的所有文件?,regex,batch-file,findstr,Regex,Batch File,Findstr,我的问题是为Windows创建一个批处理脚本文件,并遍历许多文件,然后找到每一个包含两个指定字符串的行的文件。因此,如果整个文件包含这些字符串,这还不够好,它们应该在同一行 例如,我有5个文件,其中包含以下内容: 1st: apple:green 2nd: apple green 3rd: green apple 4th: apple: yellowgreen 5th: apple: green 它应该返回第一个、第四个和第五个文件的文件名 以下是我所拥有的: FINDSTR /s /i /m

我的问题是为Windows创建一个批处理脚本文件,并遍历许多文件,然后找到每一个包含两个指定字符串的行的文件。因此,如果整个文件包含这些字符串,这还不够好,它们应该在同一行

例如,我有5个文件,其中包含以下内容:

1st: apple:green
2nd: apple
green
3rd: green
apple
4th: apple: yellowgreen
5th: apple: green
它应该返回第一个、第四个和第五个文件的文件名

以下是我所拥有的:

FINDSTR /s /i /m "apple green" *.txt | FINDSTR "\MyDirectory" >> results.txt

我应该如何修改它以使其工作?

编辑以使用FINDSTR

这个正则表达式为我工作:
“苹果。*绿色。*苹果”

另外,使用管道的write-to-file命令对我也不起作用(也许我遗漏了一些东西)。如果它对您不起作用,可能会:


FINDSTR/s/i/m“apple.*绿色。*apple”*.txt>>results.txt

有关更多解决方案,请选择最适合您的问题的答案作为公认答案。
findstr /i /s /m /r /c:"apple.*green" /c:"green.*apple" *.txt