@EXPFIND — Searches for one string within another after expanding escapes.

Syntax: %@EXPFIND[string,substring,n,flags]

stringthe string to search within
substringthe string to search for
nnth match in string
flags1: case sensitive
8: return offset and length

Use commas to separate arguments. If you need a comma in either string, either enclose the string double quotes, or else use \c or \x002c to represent the comma.

If you need a double quote in either string, use \q or \x0022 to represent it.

This function returns -1 if the substring was not found in the string, or a different value if it was. If either string or substring is empty, there is no match and the function returns -1.

The n argument can be used to look for multiple occurences of the substring in the string. If n is positive, @EXPFIND will return the nth instance of substring. If n is negative, @EXPFIND will return the last, next-to-last, etc. instance. If n is zero, @EXPFIND will return the number of matches. If n is not specified, it defaults to 1 — the first instance.

When a match is found, the return value is the zero-based offset in the original string — i.e. before any expansion of escapes. If bit 4 of flags is set, @EXPFIND returns both the offset and the length of substring, separated by a + sign. Again, these refer to the original string before any expansion of escapes.

rem   Case insensitive:
echo %@expfind[\x41\x42\x43\x44\x45\x46\x47\x48,cde]

rem   Case sensitive:
echo %@expfind[\x41\x42\x43\x44\x45\x46\x47\x48,cde,,1]

There may be multiple matches in one string. You can use the n argument to select each:

for /l %i in ( 0, 1, 5 ) echo %i - %@expfind["B\x61n\x61n\x61 b\x61n\x61n\x61r\x61m\x61!",ana,%i]