A regexp to parse color escape sequence could be:
m/\\033\[(\d+)(?:;(\d+)(?:;(\d+))?)?m/;
I tested three cases:
- \033[0m, gives me $1 = 0, $2 and $3 undefined. Correct;
- \033[1;31m, gives me $1 = 1, $2 = 31, and $3 undefined. Correct;
- \033[1;31;44m, gives me $1 = 1, $2 = 31, and $3 = 44. Correct.