findstr

Why does findstr not handle case properly (in some circumstances)?

半世苍凉 提交于 2019-11-27 04:32:16
While writing some recent scripts in cmd.exe, I had a need to use findstr with regular expressions - customer required standard cmd.exe commands (no GnuWin32 nor Cygwin nor VBS nor Powershell). I just wanted to know if a variable contained any upper-case characters and attempted to use: > set myvar=abc > echo %myvar%|findstr /r "[A-Z]" abc > echo %errorlevel% 0 When %myvar% is set to abc , that actually outputs the string and sets errorlevel to 0, saying that a match was found. However, the full-list variant: > echo %myvar%|findstr /r "[ABCDEFGHIJKLMNOPQRSTUVWXYZ]" > echo %errorlevel% 1 does

Regular expressions in findstr

时光毁灭记忆、已成空白 提交于 2019-11-27 01:09:44
问题 I'm doing a little string validation with findstr and its /r flag to allow for regular expressions. In particular I'd like to validate integers. The regex ^[0-9][0-9]*$ worked fine for non-negative numbers but since I now support negative numbers as well I tried ^([1-9][0-9]*|0|-[1-9][0-9]*)$ for either positive or negative integers or zero. The regex works fine theoretically . I tested it in PowerShell and it matches what I want. However, with findstr /r /c:"^([1-9][0-9]*|0|-[1-9][0-9]*)$"

Findstr always fails to find hash string in text file

天大地大妈咪最大 提交于 2019-11-26 21:59:19
问题 I'm trying to replace a certain .jar file if the MD5 hash of the file changes. I've written a small PowerShell script to do the hashing of the file and the .ps1 script is run through a batch file. After PowerShell prints the hash into 1.txt I want the batch script to check the text file for the correct hash and if the hash is different it will overwrite the file with the old version. The replacing of the file is not yet implemented but will be once the findstr issue is resolved. @echo off

Regex - how to match everything except a particular pattern

最后都变了- 提交于 2019-11-26 14:58:29
How do I write a regex to match any string that doesn't meet a particular pattern? I'm faced with a situation where I have to match an (A and ~B) pattern. Gumbo You could use a look-ahead assertion: (?!999)\d{3} This example matches three digits other than 999 . But if you happen not to have a regular expression implementation with this feature (see Comparison of Regular Expression Flavors ), you probably have to build a regular expression with the basic features on your own. A compatible regular expression with basic syntax only would be: [0-8]\d\d|\d[0-8]\d|\d\d[0-8] This does also match any

Regex - how to match everything except a particular pattern

跟風遠走 提交于 2019-11-26 06:04:50
问题 How do I write a regex to match any string that doesn\'t meet a particular pattern? I\'m faced with a situation where I have to match an (A and ~B) pattern. 回答1: You could use a look-ahead assertion: (?!999)\d{3} This example matches three digits other than 999 . But if you happen not to have a regular expression implementation with this feature (see Comparison of Regular Expression Flavors), you probably have to build a regular expression with the basic features on your own. A compatible

Why doesn't this FINDSTR example with multiple literal search strings find a match?

可紊 提交于 2019-11-26 00:55:50
问题 The following FINDSTR example fails to find a match. echo ffffaaa|findstr /l \"ffffaaa faffaffddd\" Why? 回答1: Apparantly this is a long standing FINDSTR bug. I think it can be a crippling bug, depending on the circumstances. I have confirmed the command fails on two different Vista machines, a Windows 7 machine, and an XP machine. I found this findstr - broken ??? link that reports a similar search fails on Windows Server 2003, but it succeeds on Windows 2000. I've done a number of

Why doesn't this FINDSTR example with multiple literal search strings find a match?

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-25 19:58:23
The following FINDSTR example fails to find a match. echo ffffaaa|findstr /l "ffffaaa faffaffddd" Why? dbenham Apparantly this is a long standing FINDSTR bug. I think it can be a crippling bug, depending on the circumstances. I have confirmed the command fails on two different Vista machines, a Windows 7 machine, and an XP machine. I found this findstr - broken ??? link that reports a similar search fails on Windows Server 2003, but it succeeds on Windows 2000. I've done a number of experiments and it seems all of the following conditions must be met for the potential of a failure: The search