That should be `r"^((\d+;)*(\d+))([a-zA-Z])"` (removed the second `*`).  If the idea is to match only SGR (color commands), then the character class at the end should be replaced by `m`: `r"^((\d+;)*(\d+))m"`