Mr Mystery Guest
Mr Mystery Guest

Reputation: 1474

Wildcard in batch file

I was wondering how to check for a wildcard in a batch file

SET /p project=Enter project (XYZ_2016_123)

I need to be able to check if the variable project is in the format XYZ_20??_123 where ?? are two digits. Ignore the XYZ & 123 part of the input. At the moment I have lots of if statements to check if the year. But I was wondering if could be done with wildcards?

s=%project%
if not x%s:XYZ_2016_123=%==x%s% GOTO MAIN
if not x%s:XYZ_2017_123=%==x%s% GOTO MAIN
if not x%s:XYZ_2018_123=%==x%s% GOTO MAIN
:: etc.

Upvotes: 3

Views: 1507

Answers (1)

npocmaka
npocmaka

Reputation: 57252

try like this :

echo %s%|findstr /r "XYZ_20[0-9][0-9]_123" >nul 2>nul && (
  GOTO MAIN
)

FINDSTR

Upvotes: 4

Related Questions