如何在批处理文件的字符串变量中检查包含子字符串?
例如:
set var1=foobarfoo
set regexp=.*bar.*
if [check var1 by regexp] echo "YES"
在我的情况下,它必须只能通过正则表达式检查,并且只能在.bat文件中检查。
答案 0 :(得分:3)
调整找到的答案here给
@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
)