如何从字符串中正确匹配出小数(带符号)字符串?
使用 string.gmatch
说明见官方文档,摘录如下:
string.gmatch (s, pattern)
Returns an iterator function that, each time it is called, returns the next captures from pattern
over string s
.
If pattern
specifies no captures, then the whole match is produced in each call.
As an example, the following loop
s = "hello world from Lua" for w in string.gmatch(s, "%a+") do print(w) end
will iterate over all the words from string s
, printing one per line. The next example collects all pairs key=value
from the given string into a table:
t = {} s = "from=world, to=Lua" for k, v in string.gmatch(s, "(%w+)=(%