im running a command to get the version of a program.
FOR /F "tokens=* USEBACKQ" %%F IN (`"%programpath%\bin\program" version`) DO (
set version_full=%%F
)
the result:
Program Final Type 6.6.8 (build v3425fw2f24)
The Program Final Type part can vary. There are different types of this program. Hence why I need to use regex to find the version.
I need to get just the 6.6.8 out of this string and set it to a variable called "version_num". But I actually want it to be 6.6.8.0 if its only three numbers.
Sometimes the version can be 4 digits... like 6.6.8.2. I need to get all 4 numbers if 4 .. or if 3 make it 4 by adding a 0 at the end.
I tried
findstr /R "[0-9].[0.9].[0.9]" %version_full%
But i just get the entire string separated I think byspaces in an error like this:
FINDSTR: Cannot open 6.6.8
So its obviously not finding it.
EDIT:
I've gotten this to work to tell me if its found or not found, but I still cant get the actual found value into a variable.
@echo off
set var1=Program One New 6.6.8 (build ee27a8rr43e)
set "regexp=.*[0-9].[0-9].[0-9].*"
echo %var1%
echo %regexp%
echo %var1%|findstr /r /C:"%regexp%" >nul 2>&1 && echo Found || echo Not found.
Found
FINDSTR
outputs the whole matched string.echo
through a pipe tofindstr
:echo %version_full%|findstr [0-9].[0.9].[0.9]
. Check out: stackoverflow.com/questions/5491383/…