gpt4 book ai didi

Lua 模式 - 魔兽世界 - 八零数据库 80wdb.com

转载 作者:行者123 更新时间:2023-12-02 14:56:12 26 4
gpt4 key购买 nike

我正在尝试从游戏聊天中获取一些数据,但无法找出其中的模式。

它是魔兽世界 Vanilla (私有(private)服务器)的附加组件。

gsub函数:
http://wowprogramming.com/docs/api/gsub
http://wowwiki.wikia.com/wiki/API_gsub

我在this方面一直表现得很好解释,但现在有一部分我有这样的东西:

variable = gsub(string, "([%d+d]+)?...", "")

我不知道该模式应该是什么,因为字符串可能类似于以下示例之一:

2d17h6m31s
1d8h31m40s
22h40m4s
8h6m57s
5m25s
37s

"([%d+d]+)?"实际上是我多次尝试的组合。

我确实读过有关魔法角色的内容 ( ) . % + - * ? [ ^ $但还有一些我不明白的地方。如果我能得到一个简单的简历解释那就太好了!

聊天的重要部分:

chat

编辑 (ktb's comment):

问题:我怎样才能获取完整的“99d23h59m59s”(^(.*s)没有做到这一点)?

99d23h59m59s99可以是从 1 到 99 并且它总是有 d紧随其后,但如果确实有 <number>d 则它是可选的或不。然后同样到<number>h (数字范围从 1 到 24),<number>m (数字范围从 1 到 59)。 总是 ago最后。

更新:

/run for key in pairs(string)do ChatFrame1:AddMessage(key)end

通过该命令,我获得了 string.functionName() 的所有函数名称。 ,这是列表:

string.sub()

string.gfind()

string.rep()

string.gsub()

string.char()

string.dump()

string.find()

string.upper()

string.len()

string.format()

string.byte()

string.lower()

信息更新:

Unlike several other scripting languages, Lua does not use POSIX regular expressions (regexp) for pattern matching. The main reason for this is size: A typical implementation of POSIX regexp takes more than 4,000 lines of code. This is bigger than all Lua standard libraries together. In comparison, the implementation of pattern matching in Lua has less than 500 lines. Of course, the pattern matching in Lua cannot do all that a full POSIX implementation does. Nevertheless, pattern matching in Lua is a powerful tool and includes some features that are difficult to match with standard POSIX implementations.

Source .

Unlike some other systems, in Lua a modifier can only be applied to a character class; there is no way to group patterns under a modifier. For instance, there is no pattern that matches an optional word (unless the word has only one letter). Usually you can circumvent this limitation using some of the advanced techniques that we will see later.

Source .

我找不到上面引用中提到的“高级技术”。我只找到this我还不确定。

最佳答案

function get_time_stamp(str)
local s,m,h,d = string.match(str:reverse(),"oga s(%d*)m?(%d*)h?(%d*)d?(%d*)")
return d and d:reverse() or 0, h and h:reverse() or 0, m and m:reverse() or 0, s and s:reverse() or 0
end
local day,hour,minute,second = get_time_stamp("2d17h6m31s ago")
print (day,hour,minute,second) -- output: 2 17 6 31

day,hour,minute,second = get_time_stamp("5m25s ago")
print (day,hour,minute,second) -- output: 0 0 5 25

如果你想知道为什么我使用反向,那是因为我们肯定知道第二个总是存在,但其他的不会,如果我们不使用反向那么我们将不知道输出时数字的顺序通过字符串.match。这是我的意思的例子,如果你做了 local d,h,m,s = string.match("5m25s ago","(%d*)d?(%d*)h?(%d* )m?(%d+)s ago") 那么 print(d,h,m,s) 会说天是 5,秒是 25。相反,我们绝对确定输出的顺序。

关于Lua 模式 - 魔兽世界 - 八零数据库 80wdb.com,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42168811/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com