String.match() not working

local match = string.match("1609240-1_1609240-2_1609240-3", "1609240-1")
print(match)

This prints nil even though the shorter string is included in the longer string. Anyone know what I’m doing wrong? Also tried string.find() and it still did not work.

You have to add a percentage at the last -

local match = string.match("1609240-1_1609240-2_1609240-3", "1609240%-1")
print(match)
2 Likes

Amazing it worked, thank you very much! Any chance you could tell me why for the future?

I think it’s because so Lua adds the “-” as a character (if you use the %)

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.