Pattern Precedence

Back in Day 2, you might remember we had a little chart that showed the precedence of the various operators, and allowed you to figure out which parts of an expression would evaluate first in a larger expression. Metacharacters in patterns have the same sort of precedence rules, so you can figure out which characters or groups of characters those metacharacters refer to. Table 9.3 shows that precedence, where characters closer to the top of the table group tighter than those lower down.

Table 9.3. Pattern Metacharacter Precedence
Character Meaning
( ) grouping and memory
? + * { } quantifiers
x x $ ^ (?= ) (?!) characters, anchors, look-ahead
| alternation

As with expressions, you can group characters with () to force them to be evaluated as a sequence.

Note

You haven't learned about all these metacharacters yet. Tomorrow, we'll explore more of them.


..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset