String match parameters for string starting with %

Hey I got a simple request.

I’d like to know how to detect when a string starts with %, however it doesn’t work to just do string.match(s,"^%").

Tips?

The first problem is that you must do “%%” to find a match. I believe something like this would work (I may be wrong, I don’t use string formats much)

string.match(s," %%%s")

I had a problem with that too. I ended up using $ instead.

‘^%%’ is the search pattern you’re looking for.

local s1 = "%Hello world!"
print(string.find(s1, "^%%")) --1 1

local s2 = "Hello world!"
print(string.find(s2, "^%%")) --nil