Once you have constructed a regular expression, it is evaluated much like an arithmetic expression, that is, it is evaluated from left to right and follows an order of precedence.
The following table illustrates, from highest to lowest, the order of precedence of the various regular expression operators:
Operator(s) | Description |
---|---|
\ | Escape |
(), (?:), (?=), [] | Parentheses and Brackets |
*, +, ?, {n}, {n,}, {n,m} | Quantifiers |
^, $, \anymetacharacter | Anchors and Sequences |
| | Alternation |