For instance,
string.gsub("1111", "11", ".") --> "1..1"
would be correct if there were no specified order.
This cannot be correct, each substitution replaces 2 characters by 1, so if you find two dots, you made 2 replacements, reducing thé length by 2, and the result must be ".."
However you could eventually get "1.1" with one replacement starting in the middle