Multiple RegEx in findstr /r /c:"RegExs"

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
JuanMa777
Posts: 17
Joined: 06 Nov 2016 13:15
Location: La Plata, ¡Argentina!

Multiple RegEx in findstr /r /c:"RegExs"

#1 Post by JuanMa777 » 16 Mar 2017 14:28

Hi,
I wrote this code:

Code: Select all

@echo off
title version detection
cls
for /f "tokens=*" %%n in ('ver ^| findstr /r /c:"[ ]6"') do set ver_1="%%n"
for /f "tokens=*" %%n in ('ver ^| findstr /r /c:"[ ]10"') do set ver_2="%%n"
if /i [%ver_1%]==[] (echo Vista and older) else goto code_2
if /i [%ver_2%]==[] (echo Vista and older) else goto code_2
:code_2
echo Vista and newer!
exit


I need to put both RegEx in the same findstr, to simplify the code, and mainly to avoid this output when work with Windows 10:
Vista and older
Vista and newer,
since Windows 10 version begins with 10 and while cmd parsing the code first read "[ ]6"

Some Idea, or some alternative solution?
Thanks and regards.

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Multiple RegEx in findstr /r /c:"RegExs"

#2 Post by aGerman » 16 Mar 2017 15:17

You need to compare both major and minor version. E.g. Vista as well as Win7 have major version 6.

Code: Select all

@echo off &setlocal
for /f "tokens=2 delims=[" %%i in ('ver') do for /f "tokens=2,3 delims=. " %%j in ("%%i") do set /a "ver=%%j*100+%%k"
echo %ver%
if %ver% leq 600 (echo Vista and older) else echo newer than Vista
pause


Steffen

JuanMa777
Posts: 17
Joined: 06 Nov 2016 13:15
Location: La Plata, ¡Argentina!

Re: Multiple RegEx in findstr /r /c:"RegExs"

#3 Post by JuanMa777 » 16 Mar 2017 16:41

Thanks Steffen, always helping me. When I can I will contribute to the forum.
I made some minor modifications, but your answer is the correct and very usefull.
I had not thought that alternative.
Regards!

Post Reply