本帖最后由 idwma 于 2024-11-8 09:06 编辑
最后一个链接失效了,只测了前面的
变量名随便输的,如果和文件里的有冲突还要改一下- #@&cls&powershell "type '%~0'|out-string|iex"&pause&exit
- $aaaa='字典.txt'
- $bbbb='原文.txt'
- $dddd='结果.txt'
- gc $aaaa|?{$_ -match '='}|%{$cccc=$_ -split '=';iex('$'+$cccc[0]+'="'+$cccc[1]+'"')}
- $table=@{}
- gc $bbbb|?{$_ -match '='}|%{
- $s=$_.trim()
- while(
- [regex]::matches($s,"\w+(?=(\((?:[^()]+|(?<Open>)\(|(?<-Open>)\))+(?(Open)(?!))\)))")|%{
- $i=$_.groups[0].value+$_.groups[1].value
- $table[$_.groups[0].value]=$_.groups[0].value+$_.groups[1].value
- if($i -match '^\w+\([^)]+\)$'){
- $s=$s -replace [regex]::Escape($i),('$table["{0}"]' -f $_.groups[0].value)
- }
- 1
- }
- ){}
-
- while(
- [regex]::matches($s,'\$\w+\[\"([^]]+)\"\]')|%{
- $g=iex "$_"
- $i=iex('$'+$_.groups[1])
- if($i -ne $null){
- $k=$g -split '[(,)]'
- $table['c']=1
- $j=[regex]::replace(
- $i,
- '(?<=[(,])[A-Z]\w*(?=[,)])',
- {$k[$table['c']++]}
- )
- $s=$s -replace [regex]::Escape("$_"),$j
- 1
- }else{
- $s=$s -replace [regex]::Escape("$_"),$g
- 1
- }
- }
- ){}
-
- $cccc=$s -split '='
- iex('$'+$cccc[0]+'="'+$cccc[1]+'"')
-
- [regex]::replace(
- $s,
- '(?<=[(,])\w+(?=[,)])',
- {
- $a=$args[0].groups[0]
- if(test-path('Variable:'+$a)){iex('$'+$a)}else{$a}
- }
- )
- }|sc $dddd
复制代码
|