/[pcre]/code/trunk/doc/html/pcrematching.html
ViewVC logotype

Diff of /code/trunk/doc/html/pcrematching.html

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

revision 211 by ph10, Thu Aug 9 09:52:43 2007 UTC revision 572 by ph10, Wed Nov 17 17:55:57 2010 UTC
# Line 96  traditional finite state machine (it kee Line 96  traditional finite state machine (it kee
96  simultaneously).  simultaneously).
97  </P>  </P>
98  <P>  <P>
99    Although the general principle of this matching algorithm is that it scans the
100    subject string only once, without backtracking, there is one exception: when a
101    lookaround assertion is encountered, the characters following or preceding the
102    current point have to be independently inspected.
103    </P>
104    <P>
105  The scan continues until either the end of the subject is reached, or there are  The scan continues until either the end of the subject is reached, or there are
106  no more unterminated paths. At this point, terminated paths represent the  no more unterminated paths. At this point, terminated paths represent the
107  different matching possibilities (if there are none, the match has failed).  different matching possibilities (if there are none, the match has failed).
108  Thus, if there is more than one possible match, this algorithm finds all of  Thus, if there is more than one possible match, this algorithm finds all of
109  them, and in particular, it finds the longest. In PCRE, there is an option to  them, and in particular, it finds the longest. The matches are returned in
110  stop the algorithm after the first match (which is necessarily the shortest)  decreasing order of length. There is an option to stop the algorithm after the
111  has been found.  first match (which is necessarily the shortest) is found.
112  </P>  </P>
113  <P>  <P>
114  Note that all the matches that are found start at the same point in the  Note that all the matches that are found start at the same point in the
115  subject. If the pattern  subject. If the pattern
116  <pre>  <pre>
117    cat(er(pillar)?)    cat(er(pillar)?)?
118  </pre>  </pre>
119  is matched against the string "the caterpillar catchment", the result will be  is matched against the string "the caterpillar catchment", the result will be
120  the three strings "cat", "cater", and "caterpillar" that start at the fourth  the three strings "caterpillar", "cater", and "cat" that start at the fifth
121  character of the subject. The algorithm does not automatically move on to find  character of the subject. The algorithm does not automatically move on to find
122  matches that start at later positions.  matches that start at later positions.
123  </P>  </P>
# Line 163  moves through the subject string one cha Line 169  moves through the subject string one cha
169  through the tree.  through the tree.
170  </P>  </P>
171  <P>  <P>
172  8. None of the backtracking control verbs such as (*PRUNE) are supported.  8. Except for (*FAIL), the backtracking control verbs such as (*PRUNE) are not
173    supported. (*FAIL) is supported, and behaves like a failing negative assertion.
174  </P>  </P>
175  <br><a name="SEC5" href="#TOC1">ADVANTAGES OF THE ALTERNATIVE ALGORITHM</a><br>  <br><a name="SEC5" href="#TOC1">ADVANTAGES OF THE ALTERNATIVE ALGORITHM</a><br>
176  <P>  <P>
# Line 176  match using the standard algorithm, you Line 183  match using the standard algorithm, you
183  callouts.  callouts.
184  </P>  </P>
185  <P>  <P>
186  2. There is much better support for partial matching. The restrictions on the  2. Because the alternative algorithm scans the subject string just once, and
 content of the pattern that apply when using the standard algorithm for partial  
 matching do not apply to the alternative algorithm. For non-anchored patterns,  
 the starting position of a partial match is available.  
 </P>  
 <P>  
 3. Because the alternative algorithm scans the subject string just once, and  
187  never needs to backtrack, it is possible to pass very long subject strings to  never needs to backtrack, it is possible to pass very long subject strings to
188  the matching function in several pieces, checking for partial matching each  the matching function in several pieces, checking for partial matching each
189  time.  time. Although it is possible to do multi-segment matching using the standard
190    algorithm (<b>pcre_exec()</b>), by retaining partially matched substrings, it is
191    more complicated. The
192    <a href="pcrepartial.html"><b>pcrepartial</b></a>
193    documentation gives details of partial matching and discusses multi-segment
194    matching.
195  </P>  </P>
196  <br><a name="SEC6" href="#TOC1">DISADVANTAGES OF THE ALTERNATIVE ALGORITHM</a><br>  <br><a name="SEC6" href="#TOC1">DISADVANTAGES OF THE ALTERNATIVE ALGORITHM</a><br>
197  <P>  <P>
# Line 214  Cambridge CB2 3QH, England. Line 220  Cambridge CB2 3QH, England.
220  </P>  </P>
221  <br><a name="SEC8" href="#TOC1">REVISION</a><br>  <br><a name="SEC8" href="#TOC1">REVISION</a><br>
222  <P>  <P>
223  Last updated: 08 August 2007  Last updated: 17 November 2010
224  <br>  <br>
225  Copyright &copy; 1997-2007 University of Cambridge.  Copyright &copy; 1997-2010 University of Cambridge.
226  <br>  <br>
227  <p>  <p>
228  Return to the <a href="index.html">PCRE index page</a>.  Return to the <a href="index.html">PCRE index page</a>.

Legend:
Removed from v.211  
changed lines
  Added in v.572

  ViewVC Help
Powered by ViewVC 1.1.5