当前位置: 首页 > 图文教程 > 脚本技术 > DOS/BAT > 查找行中的第一个数据串

DOS/BAT
用批处理实现禁止运行指定程序
批处理 Autorun 病毒清除工具
批处理FINDSTR正则表达式用法实例分析
for命令的一些bug分析
for语句中的几种分隔符形式小结
Norton Ghost批处理命令用法详细介绍
CMD CODE PAGE的概念及其设置值使用方法
批处理delims=和tokens=星号 的使用差别
在DOS方式下对注册表进行操作的代码
批处理 API实现文件下载的代码
包你学会批处理整理集合
使用脚本和批处理清除电脑中的痕迹的代码
批处理BAT加强函数代码使用说明
用批处理解决数学问题的代码
cmd下PUSHD和POPD命令使用说明
比较详细的手把手教你写批处理(willsort题注版)
在批处理文件中使用参数的方法
cmd批处理转义字符%的详细解释
超详细的CMD DOS下符号的作用参考
DOS命令批量删除文件及制作该命令的批处理命令详解

DOS/BAT 中的 查找行中的第一个数据串


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-11   浏览: 59 ::
收藏到网摘: n/a

复制代码 代码如下:

@echo off
:: 查找形如 <input name=id value=1842 type=hidden> 的记录中
:: 的第一个数字串
:: 通过探测每一个字符的类型来获取,但是效率十分低下
:: code by jm 2006-10-16 CMD@XP
set num=0
setlocal enabledelayedexpansion
for /f "delims=" %%i in (input.txt) do call :intercept "%%i"
echo value=%str_%
pause
goto :eof
:intercept
set str=%1
set str=%str:~2,-2%
if not "%str%"=="" echo. "%str:~0,1%"|findstr "[0-9]">nul && (
set num=1&set str_=!str_!%str:~0,1%&&call :intercept " !str:~1! ")||(
if %num% equ 0 call :intercept " !str:~1! "
)
goto :eof
无奈何的方案,不依赖字符前后关系,会获取 value= 后的任意值,速度非常快
更能处理形如input type=hidden name=id VALUE=465974855 <input type=hidden name=id value="1820988170"><input type=hidden name=id value=1008964101>
的字符串
@echo off
setlocal enabledelayedexpansion
FOR /f "delims=" %%i in (input.txt) do (
set "t=%%i"
set "t=!t:<= !"
set "t=!t:>= !"
set "t=!t:&= !"
set "t=!t:|= !"
call :sub !t !
)
pause
goto :eof
:sub
if "%1" == "" exit /b
if "%F%" == "1" echo %1 &set F=0
if "%1" == "value" set F=1
shift
goto sub