문제

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)

도움이 되었습니까?

해결책

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top