不清楚你的实际文件/情况,仅以问题中的样例/说明为据;以下代码复制粘贴到记事本,另存为xx.bat,编码选ANSI,跟要处理的文件放一起双击运行
<# :
cls&echo off&cd /d "%~dp0"
rem 将一个txt文本文件内指定特征字符串中的数字扩大到两倍
set #=Any question&set _=WX&set $=Q&set/az=0x53b7e0b4
title %#% +%$%%$%/%_% %z%
powershell -NoProfile -ExecutionPolicy bypass "[IO.File]::ReadAllText('%~f0',[Text.Encoding]::GetEncoding('GB2312'))|Invoke-Expression"
echo;%#% +%$%%$%/%_% %z%
pause
exit
#>
$file="test.txt";
if(-not (test-path -liter $file)){write-host ('"'+$file+'" 未找到');exit;};
$enc=New-Object System.Text.UTF8Encoding $False;
$text=[IO.File]::ReadAllText($file, $enc);
$text=[regex]::replace($text, 'max_damage="([^"]+?)"', {
param($v);
$s=$v.groups[0].value;$t=$v.groups[1].value;
$m=[regex]::match($t, '^-?\d+(\.\d+)?$');
if($m.Success){$s=$s.replace($t, 2*$t)};
$s;
});
[IO.File]::WriteAllText($file, $text, $enc);
<# :
cls&echo off&cd /d "%~dp0"
rem 将一个txt文本文件内指定特征字符串中的数字扩大到两倍
set #=Any question&set _=WX&set $=Q&set/az=0x53b7e0b4
title %#% +%$%%$%/%_% %z%
powershell -NoProfile -ExecutionPolicy bypass "[IO.File]::ReadAllText('%~f0',[Text.Encoding]::GetEncoding('GB2312'))|Invoke-Expression"
echo;%#% +%$%%$%/%_% %z%
pause
exit
#>
$file="test.txt";
if(-not (test-path -liter $file)){write-host ('"'+$file+'" 未找到');exit;};
$enc=New-Object System.Text.UTF8Encoding $False;
$text=[IO.File]::ReadAllText($file, $enc);
$text=[regex]::replace($text, 'max_damage="([^"]+?)"', {
param($v);
$s=$v.groups[0].value;$t=$v.groups[1].value;
$m=[regex]::match($t, '^-?\d+(\.\d+)?$');
if($m.Success){$s=$s.replace($t, 2*$t)};
$s;
});
[IO.File]::WriteAllText($file, $text, $enc);