如何使用Windows命令行正则表达式?

时间:2021-12-07 20:27:47

I am having trouble finding how to execute regular expressions in Windows Command Line. I would want to use regular expressions for a number of situations, but basically now all I want to do is open a file with regular expressions in its name.

我在Windows命令行中找不到如何执行正则表达式。我想在很多情况下使用正则表达式,但是现在我要做的就是打开一个文件名中包含正则表达式的文件。

Example: Start s.html works fine, but start *.html does not work. What is needed?

例如:开始。html工作得很好,但是开始。html不工作。需要是什么?

Thanks

谢谢

1 个解决方案

#1


8  

Unlike many Unix shells, the Windows command line processor does not expand wildcards automatically. It is each program's responsibility to expand wildcards as it sees fit. Many programs simply don't support wildcards at all. In those cases you can always create a FOR loop to repeatedly issue the same command on a set of files specified by a wildcard.

与许多Unix shell不同,Windows命令行处理器不会自动扩展通配符。每个程序都有责任根据需要扩展通配符。许多程序根本不支持通配符。在这些情况下,您总是可以创建一个FOR循环,在通配符指定的一组文件上反复发出相同的命令。

e.g. for %f in (*.txt) do echo %f

例如,对于(*.txt)中的%f,请执行echo %f

will echo the names of all *.txt files in a directory.

将回显所有*的名称。目录中的txt文件。

use the help command to get more detailed help on any Windows command. i.e.

使用help命令在任何Windows命令中获得更详细的帮助。即。

help for

As for regular expressions: other than findstr, I don't know of any built-in Windows command which supports regular expressions.

至于正则表达式:除了findstr之外,我不知道任何支持正则表达式的内置Windows命令。

#1


8  

Unlike many Unix shells, the Windows command line processor does not expand wildcards automatically. It is each program's responsibility to expand wildcards as it sees fit. Many programs simply don't support wildcards at all. In those cases you can always create a FOR loop to repeatedly issue the same command on a set of files specified by a wildcard.

与许多Unix shell不同,Windows命令行处理器不会自动扩展通配符。每个程序都有责任根据需要扩展通配符。许多程序根本不支持通配符。在这些情况下,您总是可以创建一个FOR循环,在通配符指定的一组文件上反复发出相同的命令。

e.g. for %f in (*.txt) do echo %f

例如,对于(*.txt)中的%f,请执行echo %f

will echo the names of all *.txt files in a directory.

将回显所有*的名称。目录中的txt文件。

use the help command to get more detailed help on any Windows command. i.e.

使用help命令在任何Windows命令中获得更详细的帮助。即。

help for

As for regular expressions: other than findstr, I don't know of any built-in Windows command which supports regular expressions.

至于正则表达式:除了findstr之外,我不知道任何支持正则表达式的内置Windows命令。