# Matches an ANSI color (?> (? (?-i)\e # An Escape \[ # Followed by a bracket (?> (?38) | (?48) | (?58));2;(?(?(?>[0-2][0-5][0-5]|[0-1]\d\d|\d{1,2})) # Red is the first 0-255 value ;(?(?>[0-2][0-5][0-5]|[0-1]\d\d|\d{1,2})) # Green is the second 0-255 value ;(?(?>[0-2][0-5][0-5]|[0-1]\d\d|\d{1,2})) # Blue is the third 0-255 value m) ) | (? (?-i)\e # An Escape \[ # Followed by a bracket (?> (?38) | (?48) | (?58));5;(?(?> (?[0-7]) # 0 -7 are standard colors m | (?(?>[8-9]|1[0-5])) # 8-15 are bright colors m | (?(?>[0-2][0-3][0-1]|[0-1]\d\d|\d{1,2})) # 16-231 are cubed colors m | (?(?>[0-2][0-5][0-5]|[0-1]\d\d|\d{1,2})) # 232-255 are grayscales m)) ) | (? \e # An Escape \[ # Followed by a bracket (?(?> (?1)?\;{0,1}(?3) | (?(?9)) | (?1)?\;{0,1}(?4) | (?(?10)))(?[0-7])m) ) | (? (?-i)\e # An Escape \[ # Followed by a bracket (?(?> (?39) # 39 Represents the default foreground color m | (?49) # 49 Represents the default background color m)) ) )