Remember how we could use brackets to group, limiting the scope of alternation?
gr(e|a)y
Well, grouping also has some other neat uses.
Firstly, we can use grouping to specify a set of multiple characters that we want
to apply a quantifier to. For example, say that we want to search a list of phone
numbers for numbers that have "8989" in them. Here's our list of numbers
(example04.txt):
8989 4325
8998 0897
8234 9889
8715 8989
We can run:
egrep '(89){2}' example04.txt
and we get:
8989 4325
8715 8989
What? Why suddenly egrep? What's wrong with plain old grep?
Sorry, but as we've seen before, not all regex tools are the same - grep doesn't support
the use of plus and intervals on a group! We'll look at some tools and what they support
later.