Skip to content

Instantly share code, notes, and snippets.

@StephaneTy-Pro
Last active December 6, 2022 08:40
Show Gist options
  • Save StephaneTy-Pro/2c2961ee0efd6451ed89 to your computer and use it in GitHub Desktop.
Save StephaneTy-Pro/2c2961ee0efd6451ed89 to your computer and use it in GitHub Desktop.
CMD: Check if a substring is in a string
:: cherche si la chaine compiled est présente dans le nom de fichier
ECHO "truc-compiled" | findstr /r /c:"compiled" > nul && SET ISFOUND=1 || SET ISFOUND=0
:: Orgigin
:: http://stackoverflow.com/questions/8756804/check-a-string-for-a-substring-in-a-batch-file-windows
:: Author dbenham
:: This regular expression example will search $1 for "BEGIN" at start of string,
:: "MID" anywhere in middle, and "END" at end. The search is case sensitive by default.
set "search=^BEGIN.*MID.*END$"
setlocal enableDelayedExpansion
echo(!$1!|findstr /r /c:"!search!" >nul && (
echo FOUND
rem any commands can go here
) || (
echo NOT FOUND
rem any commands can go here
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment