我有一个如下文件:
Line 207: ["Mystic Scroll: Shock and Swarm"] = {
Line 297: ["Mystic Scroll: Concentrated Solar Beam"] = {
Line 474: ["Mystic Scroll: Taunting Smite"] = {
Line 902: ["Mystic Scroll: Quick Exorcism"] = {
Line 1130: ["Mystic Scroll: Extended Avatar"] = {
Line 1146: ["Mystic Scroll: Hardy Shadow Word: Pain"] = {
我希望它转换成这样:
"Shock and Swarm", -- [1]
"Concentrated Solar Beam", -- [2]
"Taunting Smite", -- [3]
"Quick Exorcism", -- [4]
"Extended Avatar", -- [5]
"Hardy Shadow Word: Pain", -- [6]
我怎样才能做到这一点?(我无法手动完成,大约需要转换 3262 行)
谢谢你的协助。
答案1
您可以在 PythonScript 插件中运行 Python 脚本。
如果尚未安装,请按照此操作指导
- 创建脚本(插件>> PythonScript >> 新脚本)
- 复制此代码并保存文件(例如 format.py):
import re
counter = 0
def format(match):
global counter
counter += 1
return '"' + match.group(1) + '", -- [' + str(counter) + ']'
editor.rereplace('^[^:]+:\s+\["[^:]+:\s*([^"]+).+$', format)
- 打开要修改的文件
- 运行脚本(插件>> PythonScript >> 脚本>> 格式)
- 完毕
正则表达式解释:
^ # beginning of line
[^:]+ # 1 or more any character that is not a colon
: # a colon
\s+ # 1 or more spaces
\[ # open square bracket
" # double quote
[^:]+ # 1 or more any character that is not a colon
: # a colon
\s* # 0 or more spaces
([^"]+) # group 1, 1 or more non double quote
.+ # 1 or more any character
$ # end of line
截图(之前):
截图(之后):