Here is a simple solution that uses a handy hybrid JScript/batch utility called REPL.BAT that performs regex search and replace on stdin and writes the result to stdout. It is pure script that runs on any modern Windows machine from XP onward - no 3rd party executeable required.
It has many options, including an A
option that only lists substitued lines that match, and S
that reads from an environment variable instead of stdin. Complete documentation is embedded within the script.
Assuming REPL.BAT is in your current directory, or better yet, somewhere within your path, then the following will set value
appropriately. It will be undefined if \branches\
could not be found, or if nothing follows \branches\
:
set "mypath=c:\test\branches\9.1\_build"
set "value="
for /f "eol=\ delims=" %%A in (
'repl.bat ".*\\branches\\([^\\]*).*" "$1" AS mypath'
) do set "value=%%A"
echo %value%