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 section Backreferences, Extractions and Substitutions).
Go to the first, previous, next, last section, table of contents.