Question

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 , " ", "")
Was it helpful?

Solution

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

local phonenumber = string.gsub("123-123 -1234", "[- ]", "")
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top