[SOLVED] Pattern (Syntax) for non-negative numbers in CMD?

AlvinSeville

Prominent
Sep 7, 2020
13
0
520
Hello! I'm trying to type pattern for non-negative numbers. When I execute the following command:
Code:
echo 2223 | findstr /r "^[0-9][0-9]*$ ^+[0-9][0-9]*$"
nothing is printed (there is no match found). How to fix it? I expected 2223 as output.

Here are some examples:
  • Input: "2223", Output: "2223"
  • Input: "a2223", Output: ""
  • Input: "2223b", Output: ""
  • Input: "a", Output: ""
  • Input: "a 2223", Output: ""
  • Input: "2223 b", Output: ""
In general case if input string contains only digits (and may be "+" before them) then entire string must printed as output, but if there are some non-number symbols such as letters then nothing must be as result.

I wan't to understand which syntax to use to write '^[0-9]+$' grep equivalent:
Bash:
echo "2223" | grep --color -E '^[0-9]+$'
I know that I can use Bash on Windows (via Cygwin for instance) but it is interesting to figure out how to use regex in cmd.
 
Last edited:
Here are some examples:
  • Input: "2223", Output: "2223"
  • Input: "a2223", Output: ""
  • Input: "2223b", Output: ""
  • Input: "a", Output: ""
  • Input: "a 2223", Output: ""
  • Input: "2223 b", Output: ""
If input string contains only digits (and may be "+" before them) then entire string must printed as output, but if there are some non-number symbols such as letters then nothing must be as result.

(I've also added this in the first message.)
 
Last edited: