Next: , Previous: , Up: Regular Expressions   [Contents][Index]

3.5 Back-references and Subexpressions

The back-reference ‘\n’, where n is a single digit, matches the substring previously matched by the nth parenthesized subexpression of the regular expression. For example, ‘(a)\1’ matches ‘aa’. When used with alternation, if the group does not participate in the match then the back-reference makes the whole match fail. For example, ‘a(.)|b\1’ will not match ‘ba’. When multiple regular expressions are given with -e or from a file (‘-f file’), back-references are local to each expression.

See Known Bugs, for some known problems with back-references.