Search code examples
regexoracle-databaseoracle11goperator-precedence

Operator precedence in regular expressions


What is the default operator precedence in Oracle's regular expressions when they don't contain parentheses?

For example, given

 H|ha+

would it be evaluated as H|h and then concatenated to a as in ((H|h)a), or would the H be alternated with ha as in (H|(ha))?

Also, when does the + kick in, etc.?


Solution

  • Given the Oracle doc:

    Table 4-2 lists the list of metacharacters supported for use in regular expressions passed to SQL regular expression functions and conditions. These metacharacters conform to the POSIX standard; any differences in behavior from the standard are noted in the "Description" column.

    And taking a look at the | value in that table:

    The expression a|b matches character a or character b.

    Plus taking a look at the POSIX doc:

    Operator precedence The order of precedence for of operators is as follows:

    1. Collation-related bracket symbols [==] [::] [..]

    2. Escaped characters \

    3. Character set (bracket expression) []

    4. Grouping ()

    5. Single-character-ERE duplication * + ? {m,n}

    6. Concatenation

    7. Anchoring ^$

    8. Alternation |

    I would say that H|ha+ would be the same as (?:H|ha+).