Lua Patterns – World of Warcraft Vanilla

I tried to get some data from the game chat, but I can’t figure out this pattern.

This is an AddOn for the World of Warcraft Vanilla (Private server).

gsub function:

http://wowprogramming.com/docs/api/gsub

http://wowwiki.wikia. com/wiki/API_gsub

I have been using this explanation, but now there is a part, I have something like this:

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

I don’t know what the pattern should be, because the string can be like the following example:

< p>

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

“([%dd])? “Actually it was my many attempts.

I did read about the magic character ().% – *? [^ $ But there are still some that I don’t understand. It would be great if I could get a simple resume description!

The important part of the chat is as follows:

chat

p>

Edit (ktb’s comment):

Question: How can I get the complete “99d23h59m59s” (^(.* s) did not do this)?

In 99d23h59m59s, 99 can be 1 to 99 and it is always after d, but if it is actually d then it is optional. Then the same as h(number The range is from 1 to 24), m (the range of numbers is from 1 to 59). There will always be a period of time at the end.

Update:

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

Using this command, I got all the function names of string.functionName(), here is the list:

07005

07006

07007

07008

07009

string.dump()

070010

070011

070012

070013

070014< /p>

070015

Information update:

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 POSI X 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.

我在上”Advanced technology” is not found in the citation of. I only found this, I am not sure yet.

A few years ago I encountered the same mode limitation with the WoW plugin. It required some searching, but I dug up my parsing function.

parse_duration.lua

--
-- string:parseDuration()-parse a pseudo ISO-8601 duration of the form
-- [nd][nh][nm][ns] , where'n' is the numerical value of the time unit and
-- suffix designat es time unit as follows:'d'-days,'h'-hours,
--'m'-minutes, and,'s'-seconds. Unspecified time units have a value
-- of 0.
--

function string:parseDuration()
local ts = {d=0, h=0, m=0, s=0}
for v in self:lower():gfind("%d+[dhms]") do
ts[v:sub(-1)] = tonumber(v:sub(1,-2))
end

return ts
end

The following test your sample data.

duration_utest.lua

< /p>

require "parse_duration"

local function main()
local testSet = {
"2d17h6m31s ago something happened",
"1d8h31m40s ago something happened",
"22h40m4s ago something happened",
"8h6m57s ago something happened",
"5m25s ago something happened",
"37s ago something happened",
"10d6s alias test 1d2h3m4s should not be parsed"
}

for i,testStr in ipairs(testSet) do
- Extract timestamp portion
local tsPart = testStr:match("%S+")
local ts = tsPart:parseDuration()

io.write( tsPart, "-> {")
for k,v in pairs(ts) do
io.write(k, ":",v," ")
end
io.write( "} " )
end
end

main()< /pre>

Result

2d17h6m31s -> {m:6 d:2 s:31 h:17 }
1d8h31m40s -> {m:31 d :1 s:40 h:8 }
22h40m4s -> {m:40 d:0 s:4 h:22 }
8h6m57s -> {m:6 d:0 s:57 h:8 }
5m25s -> {m:5 d:0 s:25 h:0 }
37s -> {m:0 d:0 s:37 h:0 }
10d6s -> {m:0 d:10 s:6 h:0 }

I tried to get some data from the game chat, but I can’t figure out this pattern.

This is an AddOn for the World of Warcraft Vanilla (private server).

gsub function:

http://wowprogramming.com/docs/ api/gsub

http://wowwiki.wikia.com/wiki/API_gsub

I have been using this to explain, but now there is a part, I have something like this:< /p>

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

I don’t know what the mode should be What is it, because the string can be like the following example:

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

"([%dd])? "Actually my many attempts.

I did read about the magic character ().% – *? [^ $ But there are still some I don’t understand. If I can get the simple The resume description is great!

The important part of the chat is as follows:

chat

Edit (ktb's comment):

Question: How can I get the complete "99d23h59m59s" (^(.* s) did not do this)

In 99d23h59m59s, 99 can be 1 to 99 and it is always after d, but if it is actually d then it is optional. Then the same as h( The range of numbers is from 1 to 24), m (the range of numbers is from 1 to 59). There will always be a period of time at the end.

Update:

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

Using this command, I get all the function names of string.functionName(), here is the list:

07005

07006

07007

07008

07009

string.dump()

070010

070011

070012

070013

070014

070015

Information update:

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.

I find in the above quotation Not "advanced technology". I only found this, I'm not sure yet.

A few years ago I encountered the same mode limitation with the WoW plugin. It requires some searching, but I dug up my parsing function.

parse_duration.lua

--
-- string:parseDuration()-parse a pseudo ISO-8601 duration of the form
-- [nd][nh][nm][ns], where'n' is the numerical value of the time unit and
-- suffix designates time unit as follows:'d'-days,'h'-hours,
--'m'-minutes, and,'s'-seconds. Unspecified time units have a value
-- of 0.
--

function string:parseDuration()
local ts = {d=0, h=0, m=0 , s=0}
for v in self:lower():gfind("%d+[dhms]") do
ts[v:sub(-1)] = tonumber(v:sub( 1,-2))
end

return ts
end

The following test your sample data.

duration_utest.lua

require "parse_duration"

local function main()
local testSet = {
"2d17h6m31s ago something happened",
"1d8h31m40s ago something happened",
"22h40m4s ago something happened",
"8h6m57s ago something happened",
"5m25s ago something happened",
"37s ago something happened",
"10d6s alias test 1d2h3m4s should not be parsed"
}

for i,testStr in ipairs(testSet) do
- Extract timestamp portion
local tsPart = testStr:match("%S+ ")
local ts = tsPart:parseDuration()

io.write( tsPart, "-> {")
for k,v in pairs(ts) do
io.write(k,":",v," ")
end
io.write( "} " )
end
end

main()

Result

2d17h6m31s -> {m:6 d:2 s:31 h:17 }
1d8h31m40s -> {m:31 d:1 s:40 h:8 }
22h40m4s -> {m:40 d:0 s:4 h:22 }
8h6m57s -> {m:6 d :0 s:57 h:8 }
5m25s -> {m:5 d:0 s:25 h:0 }
37s -> {m:0 d:0 s:37 h:0 }
10d6s -> {m:0 d:10 s:6 h:0 }

Leave a Comment

Your email address will not be published.