Why does this work:
local str = "Apple13"
print(str:match("Apple1"))
Output data: “Apple1”
But this doesn’t
local str = "Apple-1-3"
print(str:match("Apple-1"))
Output data: nil
Why does this work:
local str = "Apple13"
print(str:match("Apple1"))
Output data: “Apple1”
But this doesn’t
local str = "Apple-1-3"
print(str:match("Apple-1"))
Output data: nil
Because ‘-’ is a special character and must be escaped with ‘%’ if you want to match the actual character.
https://www.lua.org/manual/5.1/manual.html#5.4.1
To match a ‘-’, try print( ("Apple-1-3"):match("Apple%-1") )
It still doens’t work. It gives me an error.
Nevermind. I had to put the % in front of the “-”
whoops you’re right, I’ve edited my previous comment
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.