@echo off
:Replace_asterisk <variable> <replacement>
setlocal EnableDelayedExpansion
set "var=%~1"
set "replace=%~2"
rem Add dummy char to accept also a star in front
set "var=#!var!"
:replaceLoop
for /F "tokens=1 delims=*" %%A in ("!var!") do (
set "prefix=%%A"
set "rest=!var:*%%A=!"
if defined rest (
set "rest=!REPLACE!!rest:~1!"
set Again=1
) else set "Again="
set "var=%%A!rest!"
)
if defined again goto :replaceLoop
set "var=!var:~1!"
echo !var!
exit /b
set "s1=1*23*ABCD**5"
set "t1=*" & set "t2=-"
(echo,%s1%>s1.n)&(for %%n in (s1.n) do set/a "m=%%~zn-3")&(del/q s1.n)
setlocal enabledelayedexpansion
for /L %%k in (0,1,%m%) do (
set "c=!s1:~%%k,1%!"
if !c! neq %t1% (set "s2=!s2!!c!") else (set "s2=!s2!%t2%")
)
echo,!s2!
endlocal &pause &exit/b