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

标签 python search notepad++ scintilla

我正在尝试自动删除我在 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/

相关文章:

search - vim — 如何搜索缓冲区?

Android,ListView 搜索/过滤 -> 重复条目

c# - 正则表达式:匹配字符集具体次数

regex - 通过正则表达式在 Notepad++ 中替换时如何使用条件

python - 如何防止在单元测试python中截断字符串

python - 如何循环遍历列表并取出几个不同的变量?

c++ - 将 numpy 指针 (dtype=np.bool) 传递给 C++

python - Conda 构造函数重复文件警告

java - 如何在字符串中搜索关键字

regex - 查找/替换正则表达式以删除 html 标签