Regular expressions in findstr Regular expressions in findstr windows windows

Regular expressions in findstr


This works for me:

findstr /r "^[1-9][0-9]*$ ^-[1-9][0-9]*$ ^0$"

If you don't use the /c option, the <Strings> argument is treated as a space-separated list of search strings, which makes the space a sort of crude replacement for the | construct. (As long as your regexes don't contain spaces, that is.)


Argh, I should have read the documentation better. findstr apparently doesn't support alternations (|).

So I'm probably back to multiple invocations or replacing the whole thing with a custom parser eventually.

This is what I do for now:

set ERROR=1rem Test for zeroecho %1|findstr /r /c:"^0$">nul 2>&1if not errorlevel 1 set ERROR=rem Test for positive numbersecho %1|findstr /r /c:"^[1-9][0-9]*$">nul 2>&1if not errorlevel 1 set ERROR=rem Test for negative numbersecho %1|findstr /r /c:"^-[1-9][0-9]*$">nul 2>&1if not errorlevel 1 set ERROR=


Or if you can, download grep for windows.. Many more features than findstr provides.