【问题标题】:Getting line of a search term - Python Script for Notepad++获取搜索词的行 - Notepad++ 的 Python 脚本
【发布时间】:2015-06-29 17:05:38
【问题描述】:

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

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

由于我不想删除第一个术语,我可以将startPosition 设置为第一个术语之后的一行。唯一的问题是我在 Python 脚本中找不到任何闪烁函数找到我正在寻找的文本。也许这个research 函数可以帮助找到解决方案:

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

但我找不到任何与 .research 相关的功能对我有帮助。

【问题讨论】:

  • 似乎您可以编写一个正则表达式来传递 Editor.research() ,该表达式将匹配包括第一个换行符在内的所有内容。 Editor.research() == (R(egular)E(xpression)Search) 我相信。

标签: python search notepad++ scintilla


【解决方案1】:
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() 因为你想使用匹配的结尾作为下一次搜索的开始

【讨论】:

  • 再次感谢您抽出宝贵时间,RaGe,一切正常。 :)
猜你喜欢
  • 1970-01-01
  • 2016-05-07
  • 1970-01-01
  • 2012-07-08
  • 1970-01-01
  • 2020-07-29
  • 2013-10-18
  • 2016-11-27
  • 1970-01-01
相关资源
最近更新 更多