How can I check contains of substring in string variable of batch file?
for example:
set var1=foobarfoo
set regexp=.*bar.*
if [check var1 by regexp] echo "YES"
In my case, it's must be only check by regular expression and only in .bat file.
How can I check contains of substring in string variable of batch file?
for example:
set var1=foobarfoo
set regexp=.*bar.*
if [check var1 by regexp] echo "YES"
In my case, it's must be only check by regular expression and only in .bat file.
Adjusting the answer found here give
@echo off
set var1=foobarfoo
set "regexp=.*bar.*"
echo %var1%
echo %regexp%
setlocal enableDelayedExpansion
echo(%var1%|findstr /r /c:"%regexp%" >nul && (
echo FOUND
rem any commands can go here
) || (
echo NOT FOUND
rem any commands can go here
)