Trying to understand grouping in extended regular expressions. What is the difference between following two extended regular expressions.
$ echo "the CPU is" | grep -E '[Tt]he CPU|computer is'
the CPU is
$ echo "the CPU is" | grep -E '[Tt]he (CPU|computer) is'
the CPU is
On my Ubuntu bash shell the grep program in the former pattern highlights the CPU in red color. In the latter pattern grep highlights the CPU is. How is grouping change the pattern matching in the two cases above.
Because they are not equivalent! For example:
[Tt]he CPU|computer ismatches[Tt]he CPUORcomputer is[Tt]he (CPU|computer) ismatches[Tt]he CPU isOR[Tt]he computer isSimilar to
a(b+c)d = abd+acdin maths, you geta(b|c)d = abd|acdin regular expressions.