/[pcre]/code/trunk/doc/pcrepattern.3
ViewVC logotype

Diff of /code/trunk/doc/pcrepattern.3

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 96 by nigel, Fri Mar 2 13:10:43 2007 UTC revision 166 by ph10, Wed May 9 14:48:28 2007 UTC
# Line 291  in the Line 291  in the
291  .\" HREF  .\" HREF
292  \fBpcreapi\fP  \fBpcreapi\fP
293  .\"  .\"
294  page). For example, in the "fr_FR" (French) locale, some character codes  page). For example, in a French locale such as "fr_FR" in Unix-like systems,
295  greater than 128 are used for accented letters, and these are matched by \ew.  or "french" in Windows, some character codes greater than 128 are used for
296    accented letters, and these are matched by \ew.
297  .P  .P
298  In UTF-8 mode, characters with values greater than 128 never match \ed, \es, or  In UTF-8 mode, characters with values greater than 128 never match \ed, \es, or
299  \ew, and always match \eD, \eS, and \eW. This is true even when Unicode  \ew, and always match \eD, \eS, and \eW. This is true even when Unicode
# Line 740  example [\ex{100}-\ex{2ff}]. Line 741  example [\ex{100}-\ex{2ff}].
741  If a range that includes letters is used when caseless matching is set, it  If a range that includes letters is used when caseless matching is set, it
742  matches the letters in either case. For example, [W-c] is equivalent to  matches the letters in either case. For example, [W-c] is equivalent to
743  [][\e\e^_`wxyzabc], matched caselessly, and in non-UTF-8 mode, if character  [][\e\e^_`wxyzabc], matched caselessly, and in non-UTF-8 mode, if character
744  tables for the "fr_FR" locale are in use, [\exc8-\excb] matches accented E  tables for a French locale are in use, [\exc8-\excb] matches accented E
745  characters in both cases. In UTF-8 mode, PCRE supports the concept of case for  characters in both cases. In UTF-8 mode, PCRE supports the concept of case for
746  characters with values greater than 128 only when it is compiled with Unicode  characters with values greater than 128 only when it is compiled with Unicode
747  property support.  property support.
# Line 1673  pattern, so instead you could use this: Line 1674  pattern, so instead you could use this:
1674    ( \e( ( (?>[^()]+) | (?1) )* \e) )    ( \e( ( (?>[^()]+) | (?1) )* \e) )
1675  .sp  .sp
1676  We have put the pattern into parentheses, and caused the recursion to refer to  We have put the pattern into parentheses, and caused the recursion to refer to
1677  them instead of the whole pattern. In a larger pattern, keeping track of  them instead of the whole pattern.
1678  parenthesis numbers can be tricky. It may be more convenient to use named  .P
1679  parentheses instead. The Perl syntax for this is (?&name); PCRE's earlier  In a larger pattern, keeping track of parenthesis numbers can be tricky. This
1680  syntax (?P>name) is also supported. We could rewrite the above example as  is made easier by the use of relative references. (A Perl 5.10 feature.)
1681  follows:  Instead of (?1) in the pattern above you can write (?-2) to refer to the second
1682    most recently opened parentheses preceding the recursion. In other words, a
1683    negative number counts capturing parentheses leftwards from the point at which
1684    it is encountered.
1685    .P
1686    It is also possible to refer to subsequently opened parentheses, by writing
1687    references such as (?+2). However, these cannot be recursive because the
1688    reference is not inside the parentheses that are referenced. They are always
1689    "subroutine" calls, as described in the next section.
1690    .P
1691    An alternative approach is to use named parentheses instead. The Perl syntax
1692    for this is (?&name); PCRE's earlier syntax (?P>name) is also supported. We
1693    could rewrite the above example as follows:
1694  .sp  .sp
1695    (?<pn> \e( ( (?>[^()]+) | (?&pn) )* \e) )    (?<pn> \e( ( (?>[^()]+) | (?&pn) )* \e) )
1696  .sp  .sp
1697  If there is more than one subpattern with the same name, the earliest one is  If there is more than one subpattern with the same name, the earliest one is
1698  used. This particular example pattern contains nested unlimited repeats, and so  used.
1699  the use of atomic grouping for matching strings of non-parentheses is important  .P
1700  when applying the pattern to strings that do not match. For example, when this  This particular example pattern that we have been looking at contains nested
1701  pattern is applied to  unlimited repeats, and so the use of atomic grouping for matching strings of
1702    non-parentheses is important when applying the pattern to strings that do not
1703    match. For example, when this pattern is applied to
1704  .sp  .sp
1705    (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa()    (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa()
1706  .sp  .sp
# Line 1737  is the actual recursive call. Line 1752  is the actual recursive call.
1752  If the syntax for a recursive subpattern reference (either by number or by  If the syntax for a recursive subpattern reference (either by number or by
1753  name) is used outside the parentheses to which it refers, it operates like a  name) is used outside the parentheses to which it refers, it operates like a
1754  subroutine in a programming language. The "called" subpattern may be defined  subroutine in a programming language. The "called" subpattern may be defined
1755  before or after the reference. An earlier example pointed out that the pattern  before or after the reference. A numbered reference can be absolute or
1756    relative, as in these examples:
1757    .sp
1758      (...(absolute)...)...(?2)...
1759      (...(relative)...)...(?-1)...
1760      (...(?+1)...(relative)...
1761    .sp
1762    An earlier example pointed out that the pattern
1763  .sp  .sp
1764    (sens|respons)e and \e1ibility    (sens|respons)e and \e1ibility
1765  .sp  .sp
# Line 1758  When a subpattern is used as a subroutin Line 1780  When a subpattern is used as a subroutin
1780  case-independence are fixed when the subpattern is defined. They cannot be  case-independence are fixed when the subpattern is defined. They cannot be
1781  changed for different calls. For example, consider this pattern:  changed for different calls. For example, consider this pattern:
1782  .sp  .sp
1783    (abc)(?i:(?1))    (abc)(?i:(?-1))
1784  .sp  .sp
1785  It matches "abcabc". It does not match "abcABC" because the change of  It matches "abcabc". It does not match "abcABC" because the change of
1786  processing option does not affect the called subpattern.  processing option does not affect the called subpattern.
# Line 1782  function is to be called. If you want to Line 1804  function is to be called. If you want to
1804  can put a number less than 256 after the letter C. The default value is zero.  can put a number less than 256 after the letter C. The default value is zero.
1805  For example, this pattern has two callout points:  For example, this pattern has two callout points:
1806  .sp  .sp
1807    (?C1)\dabc(?C2)def    (?C1)abc(?C2)def
1808  .sp  .sp
1809  If the PCRE_AUTO_CALLOUT flag is passed to \fBpcre_compile()\fP, callouts are  If the PCRE_AUTO_CALLOUT flag is passed to \fBpcre_compile()\fP, callouts are
1810  automatically installed before each item in the pattern. They are all numbered  automatically installed before each item in the pattern. They are all numbered
# Line 1804  documentation. Line 1826  documentation.
1826  .rs  .rs
1827  .sp  .sp
1828  \fBpcreapi\fP(3), \fBpcrecallout\fP(3), \fBpcrematching\fP(3), \fBpcre\fP(3).  \fBpcreapi\fP(3), \fBpcrecallout\fP(3), \fBpcrematching\fP(3), \fBpcre\fP(3).
1829  .P  .
1830  .in 0  .
1831  Last updated: 06 December 2006  .SH AUTHOR
1832  .br  .rs
1833  Copyright (c) 1997-2006 University of Cambridge.  .sp
1834    .nf
1835    Philip Hazel
1836    University Computing Service
1837    Cambridge CB2 3QH, England.
1838    .fi
1839    .
1840    .
1841    .SH REVISION
1842    .rs
1843    .sp
1844    .nf
1845    Last updated: 06 March 2007
1846    Copyright (c) 1997-2007 University of Cambridge.
1847    .fi

Legend:
Removed from v.96  
changed lines
  Added in v.166

  ViewVC Help
Powered by ViewVC 1.1.5