How would I have string.gsub() to replace 2 characters instead of 1

I’m attempting to make a TextBox that only allows numbers (“%D+”) and colons (“:”), but I don’t seem to understand how to join them together - as it only allows me to use numbers or colons - how would I make it work with colons and numbers? This is what I tried so far:

			local chars = string.len(bgTime.EndTime.Text)
			bgTime.EndTime.Text = bgTime.EndTime.Text:gsub("%D+", "") --this line
			if chars >= 5 then
				bgTime.EndTime.Text = bgTime.EndTime.Text:sub(1, 5)

Maybe bgTime.EndTime.Text:gsub("[^%d:]", "")?

(Also you could just do this and you don’t need to get the length)

bgTime.EndTime.Text = bgTime.EndTime.Text:gsub("[^%d:]", ''):sub(1, 5)
1 Like
-- count
local _, count = string.gsub(str, "[%:?%d%:?]+", "")
-- with this pattern, the only match returned will be a string containing sections that contain a colon either right before or after a number

use an anchor if you need to start matching from either side of the string.

1 Like

Where can I find a page to get those symbols? I lack the knowledge and only know a few since other assisted me, but I can’t find an accurate resource.