Name

( ) (Parentheses) — Defines a subexpression

Synopsis

Place parentheses ( () ) around a portion of a regular expression to define a subexpression. Subexpressions are useful for the following purposes:

  • To constrain an alternation to the subexpression.

  • To provide for a backreference to the value matched by the subexpression.

  • To allow a quantifier to be applied to the subexpression as a whole.

The regular expression in the following example uses parentheses twice. The innermost set constrains the alternation to the three fruit names. The outermost set defines a subexpression in the form of fruit name + space, which we require to appear from 1 to 3 times in the text.

SELECT REGEXP_SUBSTR( 
   'orange apple pear lemon lime',
   'orange ((apple|pear|lemon)[[:space:]]){1,3}')
FROM dual;

orange apple pear lemon

See Section 1.6, especially under Section 1.6.6 and Section 1.6.8, for more examples showing the use of parentheses in regular expressions.

Get Oracle Regular Expressions Pocket Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.