使用 Lua,我使用以下模式从大型 XML 字符串中解析最后出现的 XML 标记:
local firstPattern = "<tag>(.-)</tag>"
然后,我使用以下代码查找每个事件:
local lastMatch
for match in string.gmatch(xmlString, firstPattern) do
lastMatch = match
end
它看起来不是很快,所以我尝试在模式的开头添加一个贪婪字符:
local secondPattern = ".*<tag>(.-)</tag>"
lastMatch = string.match(xmlString, secondPattern)
在解析之前和之后打印os.clock()
我发现第二个模式稍微快一些,但我必须认为有更好的模式来匹配最后一次出现的 xml 标记。
我也尝试了第三种模式,但它只返回 xml 标记的第一个实例。
local thirdPattern = "<tag>(.-)</tag>.-$"
local firstMatch = string.match(xmlString, thirdPattern)