RegEx/ANSI/4BitColor.regex.txt

# Matches an ANSI 3 or 4-bit color
\e # An Escape
\[ # Followed by a bracket
(?<Color>(?>
  (?<IsBright>1)?\;{0,1} # A 1 and a semicolon indicate a bright color
(?<IsForegroundColor>3) # A number that starts with 3 indicates foreground color
  |
  (?<IsBright>(?<IsForegroundColor>9)) # OR it could be a less common bright foreground color, which starts with 9
  |
  (?<IsBright>1)?\;{0,1} # A 1 and a semicolon indicate a bright color
(?<IsBackgroundColor>4) # A number that starts with 3 indicates foreground color
  |
  (?<IsBright>(?<IsBackgroundColor>10)) # OR it could be a less common bright foreground color, which starts with 9
)(?<ColorNumber>[0-7]) # The color number will be between 0 and 7
(?:\;{0,1}(?<IsBright>1)?)? # Brightness can also come after a color
m)