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. There is an option to stop the 
them, and in particular, it finds the longest. The matches are returned in 
110 
algorithm after the first match (which is necessarily the shortest) is found. 
decreasing order of length. There is an option to stop the algorithm after the 
111 

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> 
186 
2. Because the alternative algorithm scans the subject string just once, and 
2. 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. It is possible to do multisegment matching using <b>pcre_exec()</b> (by 
time. Although it is possible to do multisegment matching using the standard 
190 
retaining partially matched substrings), but it is more complicated. The 
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> 
<a href="pcrepartial.html"><b>pcrepartial</b></a> 
193 
documentation gives details of partial matching and discusses multisegment 
documentation gives details of partial matching and discusses multisegment 
194 
matching. 
matching. 
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: 22 October 2010 
Last updated: 17 November 2010 
224 
<br> 
<br> 
225 
Copyright © 19972010 University of Cambridge. 
Copyright © 19972010 University of Cambridge. 
226 
<br> 
<br> 