-
At the top of the precedence chart are the parentheses,
("( )"), used for grouping and memory.
Anything in parentheses will "stick together" more
tightly than anything else.
-
The second level is the quantifiers. These are the repeat
operators -- star (*), plus
(+), and question mark
(?) -- as well as the quantifiers made with
curly braces, like {5,15},
{3,}, and {5}. These always
stick to the item they're following.
-
The third level of the precedence chart holds anchors and sequence.
The anchors are the caret (^) start-of-string
anchor, the dollar-sign ($) end-of-string anchor,
the \b word-boundary anchor, and the
\B nonword-boundary anchor. Sequence (putting one
item after another) is actually an operator, even though it
doesn't use a metacharacter. That means that letters in a word
will stick together just as tightly as the anchors stick to the
letters.
-
The lowest level of precedence is the vertical bar
(|) of alternation. Since this is at the bottom of
the chart, it effectively cuts the pattern into pieces. It's at
the bottom of the chart because we want the letters in the words in
/fred|barney/ to stick together more tightly than
the alternation. If alternation were higher priority than sequence,
that pattern would mean to match fre, followed by
a choice of d or b, followed by
arney. So, alternation is at the bottom of the
chart, and the letters within the names stick together.