Example with coloring:
\documentclass{article}
\usepackage{amsmath}
\usepackage{color}
\newcommand*{\colorunderline}[2]{%
\underline{#2\color{#1}}%
}
\begin{document}
\[
\renewcommand*{\arraystretch}{1.2}
\left.\kern-\nulldelimiterspace
\begin{array}{l@{\qquad}l}
ax^2 + bx + c & (\colorunderline{red}{\text{where}\quad a \ne 1})\\
k_1 + k_2 = b & \text{and}\qquad (k_1)(k_2) = ac\\[2ex]
ax^2 + bx + c & (\colorunderline{red}{\text{where}\quad a = 1})\\
k_1 + k_2 = a & \text{and}\qquad (k_1)(k_2) =b
\end{array}
\color{red}
\right\}
\textcolor{red}{%
\begin{tabular}{@{}l@{}}
very\\
different!
\end{tabular}%
}
\]
\end{document}

The same distance of the red underline can be achieved, if the second case includes \vphantom{\ne}:
(\colorunderline{red}{\text{where}\quad a = 1\vphantom{\ne}})

Colored \underline
The "simple" definition
\newcommand*{\colorunderlinex}[2]{%
\underline{#2\color{#1}}%
}
works with a trick. First TeX processes the argument to make a math formula. \color automatically uses \aftergroup to reset the color. Then the math formula is put in a vertical box. The latest whatsit in the formula is the switch to the underline color. Then TeX puts the line below the formula. Finally the color whatsit that was set by \aftergroup resets the color after the underlined box construct.
However this is not compatible to coloring package luacolor via LuaTeX attributes. The following definition works for package luacolor. It needs package xcolor, because this package adds a concept of a current color (.).
The current color . is saved with name current. Then the color for the underline is set for the whole construct. The math formula is set with the previously saved color current:
\newcommand*{\colorunderline}{}
\def\colorunderline#1#{%
\colorunderlineAux{#1}%
}
\def\colorunderlineAux#1#2#3{%
\begingroup
\colorlet{current}{.}%
\color#1{#2}%
\underline{%
\begingroup
\color{current}#3%
\endgroup
}%
\endgroup
}
This definition also supports an optional argument with the color model the same way, \textcolor implements it.
The additional grouping level inside \underline is necessary, if the color is implemented via whatsits (package color). In the latter case the "simple" definition is more efficient, because it only uses two color whatsits instead of four in the definition for luacolor.