原以为用 findstr 的正则表达式能很轻松地完成任务,没想到还是有bug:当字符串最后一位为转义符号
^的时候,会出现错误的判断结果:
@echo off
:begin
cls
set input=
set /p input= 请输入一个字符串:
if "%input%"=="" goto begin
echo.
echo %input%|findstr "^*$">nul && echo 你输入的字符串是纯数字||(
echo %input%|findstr "^*$">nul && echo 你输入的字符串是纯字母||echo 你输入的字符串既不是纯数字也不是纯字母
)
echo.
pause
goto begin
I thought that using the regular expression of findstr would easily complete the task, but unexpectedly there was still a bug: when the last character of the string is the escape character
^, an incorrect judgment result will appear:
@echo off
:begin
cls
set input=
set /p input= Please enter a string:
if "%input%"=="" goto begin
echo.
echo %input%|findstr "^*$">nul && echo The string you entered is purely numeric||(
echo %input%|findstr "^*$">nul && echo The string you entered is purely alphabetic||echo The string you entered is neither purely numeric nor purely alphabetic
)
echo.
pause
goto begin