Search code examples
luastring-matching

Lua: match string but ignore same string if it matches between double columns


I have a string like this:

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

I need to catch the last part of the string ignoring : as delimiter.

In my specific case I need to find the last 405 ignoring the :405498: :244405553: :3405: and :405: that comes first

I'm really rookie with Lua and so far I have tried to match with :(.-): but I think I'm really far away from the correct solution


Solution

  • To find last number in the string ignoring surrounded with colons:

    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