Html 查找/替换但不增加值

Html 查找/替换但不增加值,html,replace,notepad++,Html,Replace,Notepad++,我有一个.HTML文件,其中附加了许多照片,用于显示照片库。我正在用新照片替换旧照片,我想一定有比简单地复制和粘贴重复文件名更智能的方法 我希望能够在每次替换时替换并增加一个文件名,从我选择的基本文件名开始。例如 ...images/69thStreet010.jpg ...images/69thStreet011.jpg ...images/69thStreet012.jpg 基本上执行CTRL+F并将“69thStreet010.jpg”替换为 ...images/xyz001.jpg .

我有一个.HTML文件,其中附加了许多照片,用于显示照片库。我正在用新照片替换旧照片,我想一定有比简单地复制和粘贴重复文件名更智能的方法

我希望能够在每次替换时替换并增加一个文件名,从我选择的基本文件名开始。例如

...images/69thStreet010.jpg
...images/69thStreet011.jpg
...images/69thStreet012.jpg
基本上执行CTRL+F并将“69thStreet010.jpg”替换为

...images/xyz001.jpg
...images/xyz002.jpg
...images/xyz003.jpg
等等,直到我想让它停止。这里有人有什么建议吗?非常感谢


更新:我还应该添加,我正在使用记事本++编辑我的文件

是时候学习脚本语言了。Python/Ruby/Perl可以通过使用简单的正则表达式和目录列表在几行代码中完成这项工作。

如果您的S&R支持正则表达式,请使用此命令。 搜索词:

images/69thStreet([0-9]+).jpg
替换术语:

images/xyz$1.jpg

有。使用python脚本创建照片列表,该脚本查看您想要的任何目录,并重命名或仅列出所有文件名。然后使用python脚本生成所需的HTML(此时应该非常简单)。然后复制并粘贴它


Python非常易于使用,您将能够在5分钟内下载它,并在另外10分钟内找到阅读/更改文件名的教程

我只使用Excel和记事本++

在Excel中创建一列递增的数字。然后在下一列(或上一列)中,将要合并的行与递增的数字合并。例如:

file00  |  1  |  .jpg
file00  |  2  |  .jpg
等等


然后将该内容复制/粘贴到记事本++(如果工作简单,则使用Excel的连接功能)并进行替换

好的,我想出了一个记事本++解决方案。
它确实需要您安装记事本++插件PythonScript。 这是一个类似文本键盘的增量替换

i、 e.
搜索并替换字符串中的整数值
以1(0为默认起始值)增量替换起始值:

在你的情况下是
搜索:…图像/69街[0-9]+.jpg
替换:…图像/xyz00\i(1).jpg

安装PythonScript插件。
将下面的代码另存为PythonScript,并将快捷方式(即Ctrl+i)与之关联:
然后在Notepad++中打开html文件,并在html文件上运行下面的脚本。
当搜索替换对话框提示时,输入以下两行:
…图片/69街[0-9]+.jpg
…images/xyz00\i(1).jpg

现在,所有
…图片/69thStreet010.jpg
…images/69thStreet011.jpg
…image/69thStreet012.jpg

将成为
…images/xyz001.jpg
…images/xyz002.jpg
…图像/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()
来自Npp导入的
*
输入re,字符串
#首先,我们将启动一个撤销操作,然后Ctrl-Z将撤销整个脚本的操作
editor.beginUndoAction()
expression=notepad.prompt(“在第一行输入搜索字符串,然后按Ctrl+Enter键,\n”+
“后跟第二行上的替换字符串”,
“增量搜索/替换”,
"")
expressionList=re.split(r“[\n\r]+”,表达式)
如果len(expressionList)==2:
foundCount=[0]
def增量替换(parmReplaceStr、parmFoundCount):
varPatternI=r'\\i\(?P[0-9]+)\)
varPatternIi=r'\\i'
varPatternISearch=re.search(varPatternI,parmReplaceStr)
如果varPatternISearch!=无:
varFoundCount=int(varPatternISearch.group('starting'))+parmFoundCount[0]
varReplaceString=re.sub(varPatternI,str(varFoundCount),parmReplaceStr)
elif检索(varPatternIi,parmReplaceStr)!=无:
varReplaceString=re.sub(varPatternIi,str(parmFoundCount[0]),parmReplaceStr)
parmFoundCount[0]=parmFoundCount[0]+1
返回varReplaceString
#Python正则表达式是否替换
editor.searchAnchor()
while editor.searchNext(0x00200000,expressionList[0])!=-1:
replaceSel(incrementalReplace(expressionList[1],foundCount))
editor.lineDown()
editor.searchAnchor()
#结束撤消操作,以便Ctrl-Z将撤消上述两个操作
editor.endUndoAction()
查看记事本++中的功能。您可以在要增加的区域上进行块选择,然后给它一个开始/结束范围,就可以全部设置好了


我最近也有类似的情况。我做了一点正则表达式搜索/替换,将我的文件名转换成我的“默认”格式,加上一些填充的“000”,我希望从那里开始递增。在那之后,我使用Shift+ALT阻止选择000,并使用编辑器完成其余工作。

notepad++允许您进行多行编辑。但是这里的主要问题是尽可能快地从它们所在的目录中获取所有文件名

在过去,我遇到了类似的挑战,我用这种方式解决了。 这几乎适用于所有win-vers

要列出目录中的所有文件,请在目录中创建一个bat文件

复制并粘贴以下批次代码

dir /b > filelist.txt
用名称保存文件

makefilelist.bat
你给它起的名字并不重要:重要的是文件扩展名.bat

双击刚刚保存的bat文件:批处理脚本在目录中执行clean dir命令,将输出重定向到filelist.txt文件

在不到一秒钟的时间内,您将输出保存到filelist.txt中,该文件将类似于以下内容:

当然,登录到文件列表中的名称可能会有所不同。。。脚本记录每个文件,不管它是否按顺序排列,或者它的名称是随机名称,或者包含日期-时间(时间戳)等:它记录所有内容到同一个目录中,然后执行

现在,您可以使用记事本++打开filelist.txt:首先删除报告t的列表行
filelist.txt
Image File Name 01.gif
Image File Name 02.gif
Image File Name 03.gif
Image File Name 04.gif
Image File Name 05.gif
Image File Name 06.gif
Image File Name 07.gif
Image File Name 08.gif
Image File Name 09.gif
Image File Name 10.gif
Image File Name 11.gif
Image File Name 12.gif
Image File Name 13.gif
Image File Name 14.gif
Image File Name 15.gif
Image File Name 16.gif
Image File Name 17.jpg
Image File Name 18.jpg
Image File Name 19.jpg
Image File Name 20.jpg
Image File Name 21.jpg
Image File Name 22.jpg
Image File Name 23.jpg
Image File Name 24.jpg
Image File Name 25.jpg
Image File Name 26.jpg
Image File Name 27.jpg
Image File Name 28.jpg
Image File Name 29.jpg
Image File Name 30.jpg
Image File Name 31.jpg
Image File Name 32.jpg
Image File Name 33.PNG
Image File Name 34.PNG
Image File Name 35.PNG
Image File Name 36.PNG
Image File Name 37.PNG
Image File Name 38.PNG
Image File Name 39.PNG
Image File Name 40.PNG
Image File Name 41.PNG
Image File Name 42.PNG
Image File Name 43.PNG
Image File Name 44.PNG
Image File Name 45.PNG
Image File Name 46.PNG
Image File Name 47.PNG
Image File Name 48.PNG
makelist.bat
dir *.jpg /b > filelist.txt
Image File Name 17.jpg
Image File Name 18.jpg
Image File Name 19.jpg
Image File Name 20.jpg
Image File Name 21.jpg
Image File Name 22.jpg
Image File Name 23.jpg
Image File Name 24.jpg
Image File Name 25.jpg
Image File Name 26.jpg
Image File Name 27.jpg
Image File Name 28.jpg
Image File Name 29.jpg
Image File Name 30.jpg
Image File Name 31.jpg
Image File Name 32.jpg