s = "I:1234,3450,i:9867" s1 = string.gsub(string.gsub(s, "[iI]:", ""), "(%d+)", "i:%1") print(s1) i:1234,i:3450,i:9867