The order of precedence for pattern matching is as follows:

  1. {}

  2. :

  3. whitespace . ..

  4. ?

  5. |

    The alternative operator has the lowest precedence. For example, suppose there are four patterns: A, B, C, and D.

    A B|C D
    

    is equivalent to

    {A B}|{C D}
    

    The example matches an input of A followed by B, or it matches an input of C followed by D.

    Grouping patterns by using the braces has the highest level of precedence. For the patterns A, B, C, and D:

    {A|B} C D
    

    is not equivalent to

    A|B C D