PREV UP NEXT Rx

3.4: Subexpressions

A subexpression is a regular expression enclosed in \( and \). A subexpression can be used anywhere a single character or character set can be used.

Subexpressions are useful for grouping regexp constructs. For example, the repeat operator, *, usually applies to just the preceeding character. Recall that:

smooo*th

matches

smooth
smoooth
...

Using a subexpression, we can apply * to a longer string:

banan\(an\)*a

matches

banana
bananana
banananana
...

Subexpressions also have a special meaning with regard to backreferences and substitutions (see See Backreferences).


Doc Search Man Page Site Search Web Search