Question

I'm using Lua string.match to extract some values of a HTML but I'm having some problems with some attributes.

To extract a phone number like this: 0000-0000, I'm using the mask:

local value = string.match(STRING, "%d%d%d%d-%d%d%d%d")

But Lua is returning something like this: "0000000"

Where is the "-" in the middle of the mask string?

And is there any way to do something like this:

"%d[4]-%d[4]" (specifying how many chars will appear in string)

Était-ce utile?

La solution

- is a special control character in Lua patterns. Since you want the literal - character, you need to escape it with the % character. So use %-.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top