好的,我想出了一个 Notepad++ 解决方案。
它确实需要您安装 Notepad++ 插件 PythonScript。这是一个类似于 TextPad 的增量替换。
即
在字符串中搜索和替换整数值,
从 1 开始递增替换(0 是默认起始值):
在您的情况下,它将是
Search: ...images/69thStreet[0-9]+.jpg
替换: ...images/xyz00\i(1).jpg
安装 PythonScript 插件。
将下面的代码保存为 PythonScript 并关联一个快捷方式(即 Ctrl+i):
然后在 Notepad++ 中打开您的 html 文件并在您的 html 文件上运行下面的脚本。
当搜索替换对话框提示时,输入以下 2 行:
...images/69thStreet[0-9]+.jpg
...images/xyz00\i(1).jpg
现在,所有
...images/69thStreet010.jpg
...images/69thStreet011.jpg
...images/69thStreet012.jpg 的实例
将变为
...images/xyz001.jpg
...images/xyz002.jpg
...images/xyz003.jpg
这是 PythonScript 代码
from Npp import *
import re, string
# First we'll start an undo action, then Ctrl-Z will undo the actions of the whole script
editor.beginUndoAction()
expression = notepad.prompt("Enter the search string on the first line, followed by Ctrl+Enter, \n" +
"followed by the replace string on second line",
"Incremental Search/Replace" ,
"")
expressionList = re.split(r"[\n\r]+", expression)
if len(expressionList) == 2:
foundCount = [0]
def incrementalReplace(parmReplaceStr,parmFoundCount):
varPatternI = r'\\i\((?P<starting>[0-9]+)\)'
varPatternIi = r'\\i'
varPatternISearch = re.search(varPatternI , parmReplaceStr)
if varPatternISearch != None:
varFoundCount = int(varPatternISearch.group('starting')) + parmFoundCount[0]
varReplaceString = re.sub(varPatternI ,str(varFoundCount ),parmReplaceStr)
elif re.search(varPatternIi, parmReplaceStr) != None:
varReplaceString = re.sub(varPatternIi,str(parmFoundCount[0]),parmReplaceStr)
parmFoundCount[0] = parmFoundCount[0] + 1
return varReplaceString
# Do a Python regular expression replace
editor.searchAnchor()
while editor.searchNext(0x00200000,expressionList[0]) != -1:
editor.replaceSel(incrementalReplace(expressionList[1],foundCount))
editor.lineDown()
editor.searchAnchor()
# End the undo action, so Ctrl-Z will undo the above two actions
editor.endUndoAction()