【问题标题】:string.match doesn't work in Lua for loopstring.match 在 Lua for 循环中不起作用
【发布时间】:2014-08-25 21:40:47
【问题描述】:

我正在尝试使用 for 循环来获取网络论坛中每个帖子的作者姓名、ID 和内容。 我试过这个,但它不起作用。如果没有 for 循环,我将得到文档中正则表达式的第一个结果。 有什么建议么?

for author_id, author_name, author_joined, author_posts, post_date, post_content in
                string.match(content, 
                "<span class=\"name\"><a name=\"(%d-)\"></a><b>([^<]+).-Joined: ([^<]+).-Posts: ([^<]+).-<span class=\"postdetails\">Posted: ([^<]+).-<span class=\"postbody\">(.-)</span><span class=\"postbody\"></span>")
        do
             document:appendContent("Name: " .. author_name)
        end
end

【问题讨论】:

    标签: for-loop lua lua-patterns


    【解决方案1】:

    要在通用for 循环中使用,您需要一个迭代器,使用string.gmatch全局匹配)而不是string.match

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-04-13
      • 2013-12-31
      • 2017-01-14
      • 2011-07-21
      • 2016-02-05
      • 2014-02-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多