我的文件中有一个字符串,例如,
async.AsyncTranslationThread - processPart: Finished Processing job number: J215577 partID: 151269
还有更多。
我只想返回包含子字符串已完成处理作业编号的行
我用正则表达式编写了一个 findstr 命令,例如
findstr /R "^.*Finished\sProcessing\sjob\snumber.*$" filename
我没有得到任何返回,要获取其中包含子字符串的字符串,正则表达式会发生什么变化?
最佳答案
如果你看一下 the documentation , findstr
不支持大多数传统的正则表达式功能,例如您正在使用的 \s
。它甚至不支持 +
量词!
The following table lists the metacharacters that findstr accepts.
| Meta Character | Value | . | Wildcard: any character | * | Repeat: zero or more occurrences of the previous character or class | ^ | Line position: beginning of the line | $ | Line position: end of the line | [class] | Character class: any one character in a set | [^class] | Inverse class: any one character not in a set | [x-y] | Range: any characters within the specified range | \x | Escape: literal use of a metacharacter x | \<string | Word position: beginning of the word | string\> | Word position: end of the word
您可以轻松摆脱这一点,即使有多个空格或制表符,它仍然会接受它:
findstr /c:"Finished Processing job number" filename
此外,默认情况下它似乎不区分大小写
关于regex - 如何在Windows中使用findstr返回具有匹配子字符串的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53199838/