在字符串lua中查找两个数字
我希望通过某种方式使用lua来隔离以下字符串中的数字98和7525.07 “我可以确认今天的事件总数文件已上载。共有98起事件,总计7525.07” 实现这一目标的最佳方式是什么 我有这个数字,它代表了第一个数字,但我正挣扎着选择第二个数字在字符串lua中查找两个数字,lua,numbers,detection,Lua,Numbers,Detection,我希望通过某种方式使用lua来隔离以下字符串中的数字98和7525.07 “我可以确认今天的事件总数文件已上载。共有98起事件,总计7525.07” 实现这一目标的最佳方式是什么 我有这个数字,它代表了第一个数字,但我正挣扎着选择第二个数字 number = string.match( "I can confirm todays incident total file has been uploaded. There are 98 incidents totalling 7,525
number = string.match(
"I can confirm todays incident total file has been uploaded. There are 98 incidents totalling 7,525.07",
"%d+"
)
如果第一个值仅为数字字符,则可以使用此匹配:
local s = "I can confirm todays incident total file has been uploaded. There are 98 incidents totalling 7,525.07"
print (s:match(".-(%d+).-([%d%.%,]+)") )
谢谢,这太好了。你介意解释一下下面的代码吗?最后一个数字:
local x=s:match(“.-%d+.-([%d%.%,]+)”)
或x=s:match((%d+%,?%d+%。?%d+))
。是否可以删除逗号但保留小数点?您可以在匹配之前删除逗号:打印(s:gsub(“,”,”):匹配((%d-%。%d+))
它较短