'Matching a format string defining colour codes

I want to match a format string (e.g. \033[1;42;35m) in a bash function, so the function can accept different colour setting when printing text.

Example for format is \033[1;42;35m, in general \033[NA;NB;NCm and want to match the [NA;NB;NCm part.

Am playing with

if [[ "$1" =~ \[[0123456789]+;[0123456789]+;[0123456789]+m ]] ; then

The problem is the following errors

./mosc.rc: line 480: syntax error in conditional expression: unexpected token `;'
./mosc.rc: line 480: syntax error near `;['
./mosc.rc: line 480: `if [[ "\033[1;42;35m" =~ \[[0123456789]+;[0123456789]+;[0123456789]+m ]] ; then'

Escaping the ; seems to work.

if [[ "$1" =~ \[[0123456789]+\;[0123456789]+\;[0123456789]+m ]] ; then


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source