Pure batch:
for /f "delims==," %%A in ("%input:*test/time (ms)=%) do echo %%A
The search and replace within the IN clause looks for the first occurance of test/time (ms)
and replaces from the beginning of the original string to the end of the search string with nothing. The FOR /F then parses out the 100 using delimiters of =
and ,
.
The presence of enclosing quotes within the value of %input%
causes the IN() clause to look weird with no visible end quote.
It looks better with delayed expansion:
setlocal enableDelayedExpansion
for /f "delims==," %%A in ("!input:*test/time (ms)=!") do echo %%A
I prefer to keep enclosing quotes out of my variable values, and explicitly add them to my code as needed. This makes the normal expansion version look more natural (delayed expansion version remains same):
set "input=test/ing=123, hello/world=321, test/time (ms)=100, test/status=0"
for /f "delims==," %%A in ("%input:*test/time (ms)=%") do echo %%A
Batch with help of JScript
If you have my hybrid JScript/batch REPL.BAT utility, then you can use regex to be very specific in your parsing:
call repl ".*test/time \(ms\)=(.*?),.*" $1 sa input
To get the value in a variable:
set "val="
for /f "delims=" %%A in ('repl ".*test/time \(ms\)=(.*?),.*" $1 sa input') do set "val=%%A"
Note that CALL is not needed within IN() clause. It also is not needed when using pipes.