正则处理由sed来完成,故运行时请确保系统内有sed命令。- @if (0)==(0) echo off
- setlocal enabledelayedexpansion
-
- pushd %~dp0
- REM 取得名称列表
- set "strDict="
- set "nCount=0"
-
- set /p "strFile=请拖入处理文本:"
- set "strFile=!strFile:"=!"
-
- set "strFilter1=name=.[^^\"]*."
- set "strFilter2=.*name=\"\([^^\"]*\)\".*$"
- for /f "tokens=*" %%i in ('sed -n "/!strFilter1!/{s/!strFilter2!/\1/;p}" "!strFile!"') do (
- set "strTmpName=%%i"
- echo,!strDict! | findstr /i "!strTmpName!" >nul 2>nul && (
- REM 有字典存在,跳过
- ) || (
- REM 无字典,添加记录
- set /a "nCount+=1"
- set "strDict=!strDict!(!strTmpName!)"
- )
- )
- echo,总共存在变量 !nCount! 个
- set "nChar=64"
- set "strRegExp="
- for /l %%i in (1 1 !nCount!) do (
- set /a "nChar+=1"
- for /f "tokens=*" %%j in ('cscript -nologo -e:jscript %~s0 GetCharFromCode !nChar!') do set "strChar=%%j"
- call :_GetParm %%i
- )
- echo,替换变量正则表达式为 :
- echo,!strRegExp!
- echo,&echo,
-
- REM 进行关键内容替换
- for /f "tokens=*" %%i in ('echo,!strFile!') do set "strNewFile=%%~dpni_rep%%~xi"
- >"!strNewFile!" sed "!strRegExp!" "!strFile!"
- type "!strNewFile!"
-
-
- pause
- goto :EOF
-
- :_GetParm
- (
- for /f "tokens=%~1 delims=()" %%a in ('echo,!strDict!') do (
- echo,第 %%i 个变量 : %%a ==^> !strChar!
- set "strRegExp=!strRegExp!s/%%a/!strChar!/g;"
- )
- goto :EOF
- )
- @end
-
- var fun = WScript.Arguments(0);
-
- switch (fun) {
- case "GetCharFromCode":
- var nChar = parseInt(WScript.Arguments(1));
- GetCharFromCode(nChar);
- break;
-
- default:;
- }
-
- function GetCharFromCode(nChar) {
- WScript.Echo(String.fromCharCode(nChar));
- }
复制代码
|