我知道如何通过简单地使用editor:MarkerNext()
来输出匹配字符串的行(来自find命令的结果):
function print_marked_lines()
local ml = 0
local lines = {}
while true do
ml = editor:MarkerNext(ml, 2)
if (ml == -1) then break end
table.insert(lines, (editor:GetLine(ml)))
ml = ml + 1
end
local text = table.concat(lines)
print(text)
end
我不知道的是如何仅输出匹配的字符串(不像发布的片段那样输出整行)。我假设有解决方案,因为匹配的字符串被突出显示,并且必须具有一些允许提取它们的属性,但我想需要Scintilla知识,因为我在提供的SciTE绑定中找不到任何引用。
查找/匹配所有正则表达式模式“I \ w +”的示例屏幕截图:
我想输出(打印到输出窗格)所有突出显示的字符串部分
答案 0 :(得分:1)
@theta,令人讨厌的问题(至少这对我而言):)
问题是在Scite GUI“查找/替换”对话框中,您使用一个正则表达式语法来匹配模式,并使用反斜杠(例如,\s
);在Scite lua
函数中,您对模式使用不同的语法,使用百分号(相应地,%s
) - 请参阅我在Lua pattern matching vs. regular expressions - Stack Overflow中的帖子。从那里,你有这两个参考:
\l
作为实际角色类的替身(如\w
和其他人)! lua
扩展脚本中使用的正则表达式模式语法
%l
类实际存在,意味着小写字符(除了%w
和其他)! 相应地,您的功能代码(“输出(打印到输出窗格)所有突出显示的字符串部分”)将是:
function print_marked_lines()
local sel = editor:GetSelText()
for mymatch in sel:gmatch"I %w+" do -- note; a regex match!
print(mymatch)
end
end
在示例文本的输出窗格中输出:
I don
I assume
I guess
I couldn
希望这有帮助,
干杯!