Skip to main content
 首页 » 编程设计

python之获取搜索词行之Notepad++ 的 Python 脚本

2024年10月24日13yyy_WW

我正在尝试自动删除我在 Notepad++ 上编辑的 HTML 代码中的一些文本,我正在使用插件 PythonScript 来执行此操作。我只有一个问题:例如,我想删除所有 <center>除了第一个。我以为我可以使用这个功能:

Editor.rereplace("search", "replace"[, flags[, startPosition[, endPosition[, maxCount]]]]) 

因为我不想删除第一个词,我可以设置 startPosition在第一个术语之后一行。唯一的问题是我在 Python 脚本中找不到任何 Scintilla 函数来定位我要查找的文本。也许这个research函数可以帮助找到解决方案:

Editor.research(search, matchFunction[, flags[, startPosition[, endPosition[, maxCount]]]]) 

但我找不到任何与 .research 相关的函数可以帮助我。

请您参考如下方法:

matches = [] 
def match_found(m): 
    # append the match start position to the matches array 
    matches.append(m.end(0)) 
 
editor.research('pattern', match_found) 
 
matches[0]  #should now contain the index of the *end* of the first match 

m.end() 因为您想使用匹配的结束作为下一次搜索的开始