Regular expressions in findstr

Posted by Johannes Rössel on Stack Overflow See other posts from Stack Overflow or by Johannes Rössel
Published on 2010-04-10T15:10:56Z Indexed on 2010/04/10 15:13 UTC
Read the original article Hit count: 526

Filed under:
|

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]*)$"

it doesn't.

While I know that findstr doesn't have the most advanced regex support (even below Notepad++ which is probably quite an achievement), I would have expected such simple expressions to work.

Any ideas what I'm doing wrong here?

© Stack Overflow or respective owner

Related posts about regex

Related posts about findstr