【问题标题】:Ignore a certain pattern in Lua (garry's mod lua 5.1)忽略 Lua 中的某种模式(garry's mod lua 5.1)
【发布时间】:2013-08-21 09:06:28
【问题描述】:

找到了一个新的方法,一个mysql数据库的php转储和15行lua,没有找到模式。模组可以删除这个。

我试图将其分成表格的不同部分,但我不知道如何制作一个模式来忽略特定的东西。

local output = "<tr><td>ABAH</td><td>A Basic Anti Hack</td><td><a href=\"mailto:email@hotmail.de\">Clark</a></td><td><a href=\"plugins/12/sv_abah.lua\">Download</a>"

for plugin in output:gmatch("<tr>(.-%S)Download</a>") do 
    --print( plugin ) 
    for title in plugin:gmatch("<td>(.-%S)</td><td>") do 
        print(title)
    end
    for description in plugin:gmatch("</td><td>(.-%S)</t") do 
        print(description)
    end
 end

到目前为止它输出了标题和描述,还输出了邮件链接,我怎样才能让它忽略呢?

输出:

 1.ABAH
 2.<a href="mailto:email@hotmail.de">Clark</a>
 3.A Basic Anti Hack

我使用http://codepad.org/XQ6rZ6ZM 进行测试。

【问题讨论】:

  • 首先,Lua 在其标准库中不提供正则表达式。它提供的模式比实际的正则表达式。二、停止使用模式匹配来解析HTML/XML!如果你想解析这些东西,就得到一个真正的解析器
  • 真正的解析器是什么?我忘了提到我在一个叫做 Garry's Mod 的游戏中使用它。
  • 如果您可以回答并接受自己的问题,其他人也可以从您找到的解决方案中受益。

标签: regex lua


【解决方案1】:

您是否有某些原因不能简单地应用另一种模式来清除 HTML,例如:

local output = "<tr><td>ABAH</td><td>A Basic Anti Hack</td><td><a href=\"mailto:mirkoiz@hotmail.de\">Clark</a></td><td><a href=\"plugins/12/sv_abah.lua\">Download</a>"

for plugin in output:gmatch("<tr>(.-%S)Download</a>") do 

        for title in plugin:gmatch("<td>(.-%S)</td><td>") do             
        title= title:gsub('<.->','')  
        print(title)
        end
        for description in plugin:gmatch("</td><td>(.-%S)</t") do 
        description = description:gsub('<.->','')     
        print('description)
        end

end

【讨论】:

    猜你喜欢
    • 2016-08-11
    • 2023-03-19
    • 2020-08-02
    • 2021-02-26
    • 1970-01-01
    • 2012-03-15
    • 2017-02-16
    • 2017-10-20
    • 1970-01-01
    相关资源
    最近更新 更多