| www.delorie.com/gnu/docs/regex/regex_21.html | search |
![]() Buy the book! | |
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
If the syntax bit RE_NO_BK_REF isn't set, then Regex recognizes
back references. A back reference matches a specified preceding group.
The back reference operator is represented by `\digit'
anywhere after the end of a regular expression's digit-th
group (see section 3.7 Grouping Operators (( ... ) or \( ... \))).
digit must be between `1' and `9'. The matcher assigns numbers 1 through 9 to the first nine groups it encounters. By using one of `\1' through `\9' after the corresponding group's close-group operator, you can match a substring identical to the one that the group does.
Back references match according to the following (in all examples below, `(' represents the open-group, `)' the close-group, `{' the open-interval and `}' the close-interval operator):
RE_DOT_NEWLINE isn't set) string that is composed of two
identical halves; the `(.*)' matches the first half and the
`\1' matches the second half.
You can use a back reference as an argument to a repetition operator. For example, `(a(b))\2*' matches `a' followed by two or more `b's. Similarly, `(a(b))\2{3}' matches `abbbb'.
If there is no preceding digit-th subexpression, the regular expression is invalid.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
| webmaster donations bookstore | delorie software privacy |
| Copyright © 2003 by The Free Software Foundation | Updated Jun 2003 |