Pergunta

I would like to use string.gsub to search through a phone number field and remove any "-" or spaces.

Is there any way to combine the two statements I have below into one?

local phonenumber = string.gsub("123-123-1234", "-", "")
phonenumber = string.gsub(phonenumber , " ", "")
Foi útil?

Solução

Yes. The square brackets are used to group multiple elements in Lua patterns

local phonenumber = string.gsub("123-123 -1234", "[- ]", "")
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top