我正在尝试自动删除我在 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()
因为您想使用匹配的结束作为下一次搜索的开始
关于python - 获取搜索词的行 - Notepad++ 的 Python 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31121519/