Lua:匹配字符串,但如果它在双列之间匹配则忽略相同的字符串

问题描述 投票:0回答:1

我有这样的字符串:

hello item:::::405498:::244405553::3405:34:405:59:::445:447:3205:::[test] and another 405 with test

我需要捕捉字符串的最后一部分,忽略

:
作为分隔符。

在我的具体情况下,我需要找到最后一个

405
,忽略先出现的
:405498:
:244405553:
:3405:
:405:

我真的是 Lua 的菜鸟,到目前为止我已经尝试与

:(.-):
相匹配,但我认为我离正确的解决方案还很远

lua string-matching
1个回答
0
投票

要查找字符串中的最后一个数字,忽略用冒号包围:

s = "hello item:::::405498:::244405553::3405:34:405:59:::445:447:3205:::[test] and another 405 with test"
print(s:match".*%f[%d:](%d+)%f[^%d:]")  --> 405
© www.soinside.com 2019 - 2024. All rights reserved.