I am new to batch scripting. although i have shell and python solutions for this problem but got stuck in batch script.
I have string like 123_happy,
Loop (1=>1000 should be enough ;)) on the characters of the variable and find the first char not in number range. Extract the substring before:
@echo off
set z=123_happy
setlocal enabledelayedexpansion
set result=
for /L %%i in (0,1,1000) do (
set zz=!z:~%%i,1!
if x!zz!==x exit /b
if !zz! lss 0 (
set result=!z:~,%%i!
goto out
)
if !zz! gtr 9 (
set result=!z:~,%%i!
goto out
)
)
:out
echo result=!result!
result:
result=123