FINDSTR /R to verify numbers and spaces

Microsoft Windows xp professional w/serv...
June 9, 2010 at 16:48:22
Specs: Windows XP SP3
I have a project similar to the d2c routine that I
got help on here (much thanks!):

This time, I'm trying to create a d2b, where
decimals go in, binary representation comes
out. I got that part working by looping through
using %dec%%%2 to get the remainder, then
%dec%/2. Rinse. Repeat. Now I'm trying to
filter what's coming in as decimal, and I'm
attempting to verify that whatever is passed in
is all numbers, or numbers delimited by
space. Foolish me, I thought it would be easy
using FINDSTR's regex capabilities, similar to:

FOR /F "delims=" %%a IN ('ECHO %*^|FINDSTR /R "[^0-9]"') DO (
	SET NaN=%%a
		SET NaN=
		CALL All.numbers "%~nx0" "%*"
... process decimals...

where "All.numbers" is another routine that
scrubs sets of text and digits, and returns only
a group of digits, space delimited.
Unfortunately, the above only works if the
returned (or initial) argument is a solid string of
numbers. I believe what is happening is [^0-9]
is interpreting delimiting spaces as not a
number. How can I include spaces as
something that is acceptable?

I'm also curious about the following results
from a command prompt:

C:\>@echo 1234567890|FINDSTR /R "[^0-9]"

C:\>@echo 1234567890|FINDSTR /R "[^0-9]*"

I would have thought I'd get the same <NUL>
response both times. Thanks for any insight
and/or alternatives that you may all have!

See More: FINDSTR /R to verify numbers and spaces

Report •

June 9, 2010 at 17:00:17
Do you know what would be easier?

Report •

June 9, 2010 at 18:57:43
set /p xx=:
for /f "tokens=* delims=0123456789 " %%a in ("%xxt%") do set test = %%a
if "%test%" equ "" (echo all spaces and nums) else (echo NO: %test%)
::------ end snippet
don't credit me, this was handed down to me by the wise ones.
#2: asterisk is "ZERO or more occurances of previous char..."
therefore zero occurances qualifies and the null counts as a
(i suck at r/e, even the very simple ones provided by FINDSTR. I always have to goof around to get them to work right. It is satisfying when they do however.)
ps: the closest i could come with FINDSTR was:
echo ...| findstr /r "^[0-9][\ ]*[0-9]$"
which almost works except you got to trim leading and trailing spaces first, because findstr uses spaces to delimit words..

Report •

June 9, 2010 at 18:58:39
I ended up using this:
FOR /F "delims=" %%a IN ('ECHO %*^|FINDSTR /R "[a-z`~!@#$%%&*()_+={}|:;'<>?/,.]"') DO (
	SET NaN=%%a
		SET NaN=
		REM CALL All.numbers "%~nx0" "%*"

Report •

Related Solutions

June 9, 2010 at 19:12:47
Thanks nbrane!
I think I was looking at it for too long. That for loop with delims
eliminating everything I "want" and testing whatever is left over
makes sense, and seems pretty simple! The regex I came up
with to test everything under the sun just looks unrefined...

And thanks for the explanation of the splat. I was under the impression it allowed for not having to code [0-9][0-9][0-9] ad infinitum, but what you said about zero or more clears things right up...

Report •

June 9, 2010 at 20:05:27
@ Razor2.3

Yeah, but what fun is that? Sure other languages have pre-
built functions for d2c, d2b, d2x, x2d, etc., but if I'm writing
code on one machine, and want to execute it on another, I
don't want to have to worry about if some form of
python/java/rexx/whatever is installed...

I only write for myself at the moment, and enjoy doing stuff

Report •

June 9, 2010 at 20:29:52
Then do VBScript or JScript! It's native to more versions of Windows, including whatever version you're using!

Report •

Ask Question