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

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

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

revision 868 by ph10, Sun Sep 11 14:31:21 2011 UTC revision 869 by ph10, Sat Jan 14 11:16:23 2012 UTC
# Line 14  man page, in case the conversion went wr Line 14  man page, in case the conversion went wr
14  <br>  <br>
15  <ul>  <ul>
16  <li><a name="TOC1" href="#SEC1">PARTIAL MATCHING IN PCRE</a>  <li><a name="TOC1" href="#SEC1">PARTIAL MATCHING IN PCRE</a>
17  <li><a name="TOC2" href="#SEC2">PARTIAL MATCHING USING pcre_exec()</a>  <li><a name="TOC2" href="#SEC2">PARTIAL MATCHING USING pcre_exec() OR pcre16_exec()</a>
18  <li><a name="TOC3" href="#SEC3">PARTIAL MATCHING USING pcre_dfa_exec()</a>  <li><a name="TOC3" href="#SEC3">PARTIAL MATCHING USING pcre_dfa_exec() OR pcre16_dfa_exec()</a>
19  <li><a name="TOC4" href="#SEC4">PARTIAL MATCHING AND WORD BOUNDARIES</a>  <li><a name="TOC4" href="#SEC4">PARTIAL MATCHING AND WORD BOUNDARIES</a>
20  <li><a name="TOC5" href="#SEC5">FORMERLY RESTRICTED PATTERNS</a>  <li><a name="TOC5" href="#SEC5">FORMERLY RESTRICTED PATTERNS</a>
21  <li><a name="TOC6" href="#SEC6">EXAMPLE OF PARTIAL MATCHING USING PCRETEST</a>  <li><a name="TOC6" href="#SEC6">EXAMPLE OF PARTIAL MATCHING USING PCRETEST</a>
22  <li><a name="TOC7" href="#SEC7">MULTI-SEGMENT MATCHING WITH pcre_dfa_exec()</a>  <li><a name="TOC7" href="#SEC7">MULTI-SEGMENT MATCHING WITH pcre_dfa_exec() OR pcre16_dfa_exec()</a>
23  <li><a name="TOC8" href="#SEC8">MULTI-SEGMENT MATCHING WITH pcre_exec()</a>  <li><a name="TOC8" href="#SEC8">MULTI-SEGMENT MATCHING WITH pcre_exec() OR pcre16_exec()</a>
24  <li><a name="TOC9" href="#SEC9">ISSUES WITH MULTI-SEGMENT MATCHING</a>  <li><a name="TOC9" href="#SEC9">ISSUES WITH MULTI-SEGMENT MATCHING</a>
25  <li><a name="TOC10" href="#SEC10">AUTHOR</a>  <li><a name="TOC10" href="#SEC10">AUTHOR</a>
26  <li><a name="TOC11" href="#SEC11">REVISION</a>  <li><a name="TOC11" href="#SEC11">REVISION</a>
27  </ul>  </ul>
28  <br><a name="SEC1" href="#TOC1">PARTIAL MATCHING IN PCRE</a><br>  <br><a name="SEC1" href="#TOC1">PARTIAL MATCHING IN PCRE</a><br>
29  <P>  <P>
30  In normal use of PCRE, if the subject string that is passed to  In normal use of PCRE, if the subject string that is passed to a matching
31  <b>pcre_exec()</b> or <b>pcre_dfa_exec()</b> matches as far as it goes, but is  function matches as far as it goes, but is too short to match the entire
32  too short to match the entire pattern, PCRE_ERROR_NOMATCH is returned. There  pattern, PCRE_ERROR_NOMATCH is returned. There are circumstances where it might
33  are circumstances where it might be helpful to distinguish this case from other  be helpful to distinguish this case from other cases in which there is no
34  cases in which there is no match.  match.
35  </P>  </P>
36  <P>  <P>
37  Consider, for example, an application where a human is required to type in data  Consider, for example, an application where a human is required to type in data
# Line 50  long and is not all available at once. Line 50  long and is not all available at once.
50  </P>  </P>
51  <P>  <P>
52  PCRE supports partial matching by means of the PCRE_PARTIAL_SOFT and  PCRE supports partial matching by means of the PCRE_PARTIAL_SOFT and
53  PCRE_PARTIAL_HARD options, which can be set when calling <b>pcre_exec()</b> or  PCRE_PARTIAL_HARD options, which can be set when calling any of the matching
54  <b>pcre_dfa_exec()</b>. For backwards compatibility, PCRE_PARTIAL is a synonym  functions. For backwards compatibility, PCRE_PARTIAL is a synonym for
55  for PCRE_PARTIAL_SOFT. The essential difference between the two options is  PCRE_PARTIAL_SOFT. The essential difference between the two options is whether
56  whether or not a partial match is preferred to an alternative complete match,  or not a partial match is preferred to an alternative complete match, though
57  though the details differ between the two matching functions. If both options  the details differ between the two types of matching function. If both options
58  are set, PCRE_PARTIAL_HARD takes precedence.  are set, PCRE_PARTIAL_HARD takes precedence.
59  </P>  </P>
60  <P>  <P>
61  Setting a partial matching option for <b>pcre_exec()</b> disables the use of any  Setting a partial matching option disables the use of any just-in-time code
62  just-in-time code that was set up by calling <b>pcre_study()</b> with the  that was set up by studying the compiled pattern with the
63  PCRE_STUDY_JIT_COMPILE option. It also disables two of PCRE's standard  PCRE_STUDY_JIT_COMPILE option. It also disables two of PCRE's standard
64  optimizations. PCRE remembers the last literal byte in a pattern, and abandons  optimizations. PCRE remembers the last literal data unit in a pattern, and
65  matching immediately if such a byte is not present in the subject string. This  abandons matching immediately if it is not present in the subject string. This
66  optimization cannot be used for a subject string that might match only  optimization cannot be used for a subject string that might match only
67  partially. If the pattern was studied, PCRE knows the minimum length of a  partially. If the pattern was studied, PCRE knows the minimum length of a
68  matching string, and does not bother to run the matching function on shorter  matching string, and does not bother to run the matching function on shorter
69  strings. This optimization is also disabled for partial matching.  strings. This optimization is also disabled for partial matching.
70  </P>  </P>
71  <br><a name="SEC2" href="#TOC1">PARTIAL MATCHING USING pcre_exec()</a><br>  <br><a name="SEC2" href="#TOC1">PARTIAL MATCHING USING pcre_exec() OR pcre16_exec()</a><br>
72  <P>  <P>
73  A partial match occurs during a call to <b>pcre_exec()</b> when the end of the  A partial match occurs during a call to <b>pcre_exec()</b> or
74  subject string is reached successfully, but matching cannot continue because  <b>pcre16_exec()</b> when the end of the subject string is reached successfully,
75  more characters are needed. However, at least one character in the subject must  but matching cannot continue because more characters are needed. However, at
76  have been inspected. This character need not form part of the final matched  least one character in the subject must have been inspected. This character
77  string; lookbehind assertions and the \K escape sequence provide ways of  need not form part of the final matched string; lookbehind assertions and the
78  inspecting characters before the start of a matched substring. The requirement  \K escape sequence provide ways of inspecting characters before the start of a
79  for inspecting at least one character exists because an empty string can always  matched substring. The requirement for inspecting at least one character exists
80  be matched; without such a restriction there would always be a partial match of  because an empty string can always be matched; without such a restriction there
81  an empty string at the end of the subject.  would always be a partial match of an empty string at the end of the subject.
82  </P>  </P>
83  <P>  <P>
84  If there are at least two slots in the offsets vector when <b>pcre_exec()</b>  If there are at least two slots in the offsets vector when a partial match is
85  returns with a partial match, the first slot is set to the offset of the  returned, the first slot is set to the offset of the earliest character that
86  earliest character that was inspected when the partial match was found. For  was inspected. For convenience, the second offset points to the end of the
87  convenience, the second offset points to the end of the subject so that a  subject so that a substring can easily be identified.
 substring can easily be identified.  
88  </P>  </P>
89  <P>  <P>
90  For the majority of patterns, the first offset identifies the start of the  For the majority of patterns, the first offset identifies the start of the
# Line 105  What happens when a partial match is ide Line 104  What happens when a partial match is ide
104  partial matching options are set.  partial matching options are set.
105  </P>  </P>
106  <br><b>  <br><b>
107  PCRE_PARTIAL_SOFT with pcre_exec()  PCRE_PARTIAL_SOFT WITH pcre_exec() OR pcre16_exec()
108  </b><br>  </b><br>
109  <P>  <P>
110  If PCRE_PARTIAL_SOFT is set when <b>pcre_exec()</b> identifies a partial match,  If PCRE_PARTIAL_SOFT is set when <b>pcre_exec()</b> or <b>pcre16_exec()</b>
111  the partial match is remembered, but matching continues as normal, and other  identifies a partial match, the partial match is remembered, but matching
112  alternatives in the pattern are tried. If no complete match can be found,  continues as normal, and other alternatives in the pattern are tried. If no
113  <b>pcre_exec()</b> returns PCRE_ERROR_PARTIAL instead of PCRE_ERROR_NOMATCH.  complete match can be found, PCRE_ERROR_PARTIAL is returned instead of
114    PCRE_ERROR_NOMATCH.
115  </P>  </P>
116  <P>  <P>
117  This option is "soft" because it prefers a complete match over a partial match.  This option is "soft" because it prefers a complete match over a partial match.
# Line 134  example, there are two partial matches, Line 134  example, there are two partial matches,
134  matches the second alternative.)  matches the second alternative.)
135  </P>  </P>
136  <br><b>  <br><b>
137  PCRE_PARTIAL_HARD with pcre_exec()  PCRE_PARTIAL_HARD WITH pcre_exec() OR pcre16_exec()
138  </b><br>  </b><br>
139  <P>  <P>
140  If PCRE_PARTIAL_HARD is set for <b>pcre_exec()</b>, it returns  If PCRE_PARTIAL_HARD is set for <b>pcre_exec()</b> or <b>pcre16_exec()</b>,
141  PCRE_ERROR_PARTIAL as soon as a partial match is found, without continuing to  PCRE_ERROR_PARTIAL is returned as soon as a partial match is found, without
142  search for possible complete matches. This option is "hard" because it prefers  continuing to search for possible complete matches. This option is "hard"
143  an earlier partial match over a later complete match. For this reason, the  because it prefers an earlier partial match over a later complete match. For
144  assumption is made that the end of the supplied subject string may not be the  this reason, the assumption is made that the end of the supplied subject string
145  true end of the available data, and so, if \z, \Z, \b, \B, or $ are  may not be the true end of the available data, and so, if \z, \Z, \b, \B,
146  encountered at the end of the subject, the result is PCRE_ERROR_PARTIAL.  or $ are encountered at the end of the subject, the result is
147    PCRE_ERROR_PARTIAL.
148  </P>  </P>
149  <P>  <P>
150  Setting PCRE_PARTIAL_HARD also affects the way <b>pcre_exec()</b> checks UTF-8  Setting PCRE_PARTIAL_HARD also affects the way UTF-8 and UTF-16
151  subject strings for validity. Normally, an invalid UTF-8 sequence causes the  subject strings are checked for validity. Normally, an invalid sequence
152  error PCRE_ERROR_BADUTF8. However, in the special case of a truncated UTF-8  causes the error PCRE_ERROR_BADUTF8 or PCRE_ERROR_BADUTF16. However, in the
153  character at the end of the subject, PCRE_ERROR_SHORTUTF8 is returned when  special case of a truncated character at the end of the subject,
154    PCRE_ERROR_SHORTUTF8 or PCRE_ERROR_SHORTUTF16 is returned when
155  PCRE_PARTIAL_HARD is set.  PCRE_PARTIAL_HARD is set.
156  </P>  </P>
157  <br><b>  <br><b>
# Line 169  if the pattern is made ungreedy the resu Line 171  if the pattern is made ungreedy the resu
171  <pre>  <pre>
172    /dog(sbody)??/    /dog(sbody)??/
173  </pre>  </pre>
174  In this case the result is always a complete match because <b>pcre_exec()</b>  In this case the result is always a complete match because that is found first,
175  finds that first, and it never continues after finding a match. It might be  and matching never continues after finding a complete match. It might be easier
176  easier to follow this explanation by thinking of the two patterns like this:  to follow this explanation by thinking of the two patterns like this:
177  <pre>  <pre>
178    /dog(sbody)?/    is the same as  /dogsbody|dog/    /dog(sbody)?/    is the same as  /dogsbody|dog/
179    /dog(sbody)??/   is the same as  /dog|dogsbody/    /dog(sbody)??/   is the same as  /dog|dogsbody/
180  </pre>  </pre>
181  The second pattern will never match "dogsbody" when <b>pcre_exec()</b> is  The second pattern will never match "dogsbody", because it will always find the
182  used, because it will always find the shorter match first.  shorter match first.
183  </P>  </P>
184  <br><a name="SEC3" href="#TOC1">PARTIAL MATCHING USING pcre_dfa_exec()</a><br>  <br><a name="SEC3" href="#TOC1">PARTIAL MATCHING USING pcre_dfa_exec() OR pcre16_dfa_exec()</a><br>
185  <P>  <P>
186  The <b>pcre_dfa_exec()</b> function moves along the subject string character by  The DFA functions move along the subject string character by character, without
187  character, without backtracking, searching for all possible matches  backtracking, searching for all possible matches simultaneously. If the end of
188  simultaneously. If the end of the subject is reached before the end of the  the subject is reached before the end of the pattern, there is the possibility
189  pattern, there is the possibility of a partial match, again provided that at  of a partial match, again provided that at least one character has been
190  least one character has been inspected.  inspected.
191  </P>  </P>
192  <P>  <P>
193  When PCRE_PARTIAL_SOFT is set, PCRE_ERROR_PARTIAL is returned only if there  When PCRE_PARTIAL_SOFT is set, PCRE_ERROR_PARTIAL is returned only if there
# Line 196  partial match was found is set as the fi Line 198  partial match was found is set as the fi
198  at least two slots in the offsets vector.  at least two slots in the offsets vector.
199  </P>  </P>
200  <P>  <P>
201  Because <b>pcre_dfa_exec()</b> always searches for all possible matches, and  Because the DFA functions always search for all possible matches, and there is
202  there is no difference between greedy and ungreedy repetition, its behaviour is  no difference between greedy and ungreedy repetition, their behaviour is
203  different from <b>pcre_exec</b> when PCRE_PARTIAL_HARD is set. Consider the  different from the standard functions when PCRE_PARTIAL_HARD is set. Consider
204  string "dog" matched against the ungreedy pattern shown above:  the string "dog" matched against the ungreedy pattern shown above:
205  <pre>  <pre>
206    /dog(sbody)??/    /dog(sbody)??/
207  </pre>  </pre>
208  Whereas <b>pcre_exec()</b> stops as soon as it finds the complete match for  Whereas the standard functions stop as soon as they find the complete match for
209  "dog", <b>pcre_dfa_exec()</b> also finds the partial match for "dogsbody", and  "dog", the DFA functions also find the partial match for "dogsbody", and so
210  so returns that when PCRE_PARTIAL_HARD is set.  return that when PCRE_PARTIAL_HARD is set.
211  </P>  </P>
212  <br><a name="SEC4" href="#TOC1">PARTIAL MATCHING AND WORD BOUNDARIES</a><br>  <br><a name="SEC4" href="#TOC1">PARTIAL MATCHING AND WORD BOUNDARIES</a><br>
213  <P>  <P>
# Line 217  results. Consider this pattern: Line 219  results. Consider this pattern:
219  </pre>  </pre>
220  This matches "cat", provided there is a word boundary at either end. If the  This matches "cat", provided there is a word boundary at either end. If the
221  subject string is "the cat", the comparison of the final "t" with a following  subject string is "the cat", the comparison of the final "t" with a following
222  character cannot take place, so a partial match is found. However,  character cannot take place, so a partial match is found. However, normal
223  <b>pcre_exec()</b> carries on with normal matching, which matches \b at the end  matching carries on, and \b matches at the end of the subject when the last
224  of the subject when the last character is a letter, thus finding a complete  character is a letter, so a complete match is found. The result, therefore, is
225  match. The result, therefore, is <i>not</i> PCRE_ERROR_PARTIAL. The same thing  <i>not</i> PCRE_ERROR_PARTIAL. Using PCRE_PARTIAL_HARD in this case does yield
226  happens with <b>pcre_dfa_exec()</b>, because it also finds the complete match.  PCRE_ERROR_PARTIAL, because then the partial match takes precedence.
 </P>  
 <P>  
 Using PCRE_PARTIAL_HARD in this case does yield PCRE_ERROR_PARTIAL, because  
 then the partial match takes precedence.  
227  </P>  </P>
228  <br><a name="SEC5" href="#TOC1">FORMERLY RESTRICTED PATTERNS</a><br>  <br><a name="SEC5" href="#TOC1">FORMERLY RESTRICTED PATTERNS</a><br>
229  <P>  <P>
# Line 233  For releases of PCRE prior to 8.00, beca Line 231  For releases of PCRE prior to 8.00, beca
231  optimizations were implemented in the <b>pcre_exec()</b> function, the  optimizations were implemented in the <b>pcre_exec()</b> function, the
232  PCRE_PARTIAL option (predecessor of PCRE_PARTIAL_SOFT) could not be used with  PCRE_PARTIAL option (predecessor of PCRE_PARTIAL_SOFT) could not be used with
233  all patterns. From release 8.00 onwards, the restrictions no longer apply, and  all patterns. From release 8.00 onwards, the restrictions no longer apply, and
234  partial matching with <b>pcre_exec()</b> can be requested for any pattern.  partial matching with can be requested for any pattern.
235  </P>  </P>
236  <P>  <P>
237  Items that were formerly restricted were repeated single characters and  Items that were formerly restricted were repeated single characters and
# Line 265  that uses the date example quoted above: Line 263  that uses the date example quoted above:
263  The first data string is matched completely, so <b>pcretest</b> shows the  The first data string is matched completely, so <b>pcretest</b> shows the
264  matched substrings. The remaining four strings do not match the complete  matched substrings. The remaining four strings do not match the complete
265  pattern, but the first two are partial matches. Similar output is obtained  pattern, but the first two are partial matches. Similar output is obtained
266  when <b>pcre_dfa_exec()</b> is used.  if DFA matching is used.
267  </P>  </P>
268  <P>  <P>
269  If the escape sequence \P is present more than once in a <b>pcretest</b> data  If the escape sequence \P is present more than once in a <b>pcretest</b> data
270  line, the PCRE_PARTIAL_HARD option is set for the match.  line, the PCRE_PARTIAL_HARD option is set for the match.
271  </P>  </P>
272  <br><a name="SEC7" href="#TOC1">MULTI-SEGMENT MATCHING WITH pcre_dfa_exec()</a><br>  <br><a name="SEC7" href="#TOC1">MULTI-SEGMENT MATCHING WITH pcre_dfa_exec() OR pcre16_dfa_exec()</a><br>
273  <P>  <P>
274  When a partial match has been found using <b>pcre_dfa_exec()</b>, it is possible  When a partial match has been found using a DFA matching function, it is
275  to continue the match by providing additional subject data and calling  possible to continue the match by providing additional subject data and calling
276  <b>pcre_dfa_exec()</b> again with the same compiled regular expression, this  the function again with the same compiled regular expression, this time setting
277  time setting the PCRE_DFA_RESTART option. You must pass the same working  the PCRE_DFA_RESTART option. You must pass the same working space as before,
278  space as before, because this is where details of the previous partial match  because this is where details of the previous partial match are stored. Here is
279  are stored. Here is an example using <b>pcretest</b>, using the \R escape  an example using <b>pcretest</b>, using the \R escape sequence to set the
280  sequence to set the PCRE_DFA_RESTART option (\D specifies the use of  PCRE_DFA_RESTART option (\D specifies the use of the DFA matching function):
 <b>pcre_dfa_exec()</b>):  
281  <pre>  <pre>
282      re&#62; /^\d?\d(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)\d\d$/      re&#62; /^\d?\d(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)\d\d$/
283    data&#62; 23ja\P\D    data&#62; 23ja\P\D
# Line 297  program to do that if it needs to. Line 294  program to do that if it needs to.
294  <P>  <P>
295  You can set the PCRE_PARTIAL_SOFT or PCRE_PARTIAL_HARD options with  You can set the PCRE_PARTIAL_SOFT or PCRE_PARTIAL_HARD options with
296  PCRE_DFA_RESTART to continue partial matching over multiple segments. This  PCRE_DFA_RESTART to continue partial matching over multiple segments. This
297  facility can be used to pass very long subject strings to  facility can be used to pass very long subject strings to the DFA matching
298  <b>pcre_dfa_exec()</b>.  functions.
299    </P>
300    <br><a name="SEC8" href="#TOC1">MULTI-SEGMENT MATCHING WITH pcre_exec() OR pcre16_exec()</a><br>
301    <P>
302    From release 8.00, the standard matching functions can also be used to do
303    multi-segment matching. Unlike the DFA functions, it is not possible to
304    restart the previous match with a new segment of data. Instead, new data must
305    be added to the previous subject string, and the entire match re-run, starting
306    from the point where the partial match occurred. Earlier data can be discarded.
307  </P>  </P>
 <br><a name="SEC8" href="#TOC1">MULTI-SEGMENT MATCHING WITH pcre_exec()</a><br>  
308  <P>  <P>
309  From release 8.00, <b>pcre_exec()</b> can also be used to do multi-segment  It is best to use PCRE_PARTIAL_HARD in this situation, because it does not
310  matching. Unlike <b>pcre_dfa_exec()</b>, it is not possible to restart the  treat the end of a segment as the end of the subject when matching \z, \Z,
311  previous match with a new segment of data. Instead, new data must be added to  \b, \B, and $. Consider an unanchored pattern that matches dates:
 the previous subject string, and the entire match re-run, starting from the  
 point where the partial match occurred. Earlier data can be discarded. It is  
 best to use PCRE_PARTIAL_HARD in this situation, because it does not treat the  
 end of a segment as the end of the subject when matching \z, \Z, \b, \B,  
 and $. Consider an unanchored pattern that matches dates:  
312  <pre>  <pre>
313      re&#62; /\d?\d(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)\d\d/      re&#62; /\d?\d(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)\d\d/
314    data&#62; The date is 23ja\P\P    data&#62; The date is 23ja\P\P
315    Partial match: 23ja    Partial match: 23ja
316  </pre>  </pre>
317  At this stage, an application could discard the text preceding "23ja", add on  At this stage, an application could discard the text preceding "23ja", add on
318  text from the next segment, and call <b>pcre_exec()</b> again. Unlike  text from the next segment, and call the matching function again. Unlike the
319  <b>pcre_dfa_exec()</b>, the entire matching string must always be available, and  DFA matching functions the entire matching string must always be available, and
320  the complete matching process occurs for each call, so more memory and more  the complete matching process occurs for each call, so more memory and more
321  processing time is needed.  processing time is needed.
322  </P>  </P>
323  <P>  <P>
324  <b>Note:</b> If the pattern contains lookbehind assertions, or \K, or starts  <b>Note:</b> If the pattern contains lookbehind assertions, or \K, or starts
325  with \b or \B, the string that is returned for a partial match will include  with \b or \B, the string that is returned for a partial match includes
326  characters that precede the partially matched string itself, because these must  characters that precede the partially matched string itself, because these must
327  be retained when adding on more characters for a subsequent matching attempt.  be retained when adding on more characters for a subsequent matching attempt.
328  </P>  </P>
# Line 369  longer possible. Consider again this <b> Line 368  longer possible. Consider again this <b>
368     0: dogsbody     0: dogsbody
369     1: dog     1: dog
370  </pre>  </pre>
371  The first data line passes the string "dogsb" to <b>pcre_exec()</b>, setting the  The first data line passes the string "dogsb" to a standard matching function,
372  PCRE_PARTIAL_SOFT option. Although the string is a partial match for  setting the PCRE_PARTIAL_SOFT option. Although the string is a partial match
373  "dogsbody", the result is not PCRE_ERROR_PARTIAL, because the shorter string  for "dogsbody", the result is not PCRE_ERROR_PARTIAL, because the shorter
374  "dog" is a complete match. Similarly, when the subject is presented to  string "dog" is a complete match. Similarly, when the subject is presented to
375  <b>pcre_dfa_exec()</b> in several parts ("do" and "gsb" being the first two) the  a DFA matching function in several parts ("do" and "gsb" being the first two)
376  match stops when "dog" has been found, and it is not possible to continue. On  the match stops when "dog" has been found, and it is not possible to continue.
377  the other hand, if "dogsbody" is presented as a single string,  On the other hand, if "dogsbody" is presented as a single string, a DFA
378  <b>pcre_dfa_exec()</b> finds both matches.  matching function finds both matches.
379  </P>  </P>
380  <P>  <P>
381  Because of these problems, it is best to use PCRE_PARTIAL_HARD when matching  Because of these problems, it is best to use PCRE_PARTIAL_HARD when matching
# Line 390  multi-segment data. The example above th Line 389  multi-segment data. The example above th
389    data&#62; gsb\R\P\P\D    data&#62; gsb\R\P\P\D
390    Partial match: gsb    Partial match: gsb
391  </pre>  </pre>
392  4. Patterns that contain alternatives at the top level which do not all  4. Patterns that contain alternatives at the top level which do not all start
393  start with the same pattern item may not work as expected when  with the same pattern item may not work as expected when PCRE_DFA_RESTART is
394  PCRE_DFA_RESTART is used with <b>pcre_dfa_exec()</b>. For example, consider this  used. For example, consider this pattern:
 pattern:  
395  <pre>  <pre>
396    1234|3789    1234|3789
397  </pre>  </pre>
# Line 409  patterns or patterns such as: Line 407  patterns or patterns such as:
407    1234|ABCD    1234|ABCD
408  </pre>  </pre>
409  where no string can be a partial match for both alternatives. This is not a  where no string can be a partial match for both alternatives. This is not a
410  problem if <b>pcre_exec()</b> is used, because the entire match has to be rerun  problem if a standard matching function is used, because the entire match has
411  each time:  to be rerun each time:
412  <pre>  <pre>
413      re&#62; /1234|3789/      re&#62; /1234|3789/
414    data&#62; ABC123\P\P    data&#62; ABC123\P\P
# Line 419  each time: Line 417  each time:
417     0: 3789     0: 3789
418  </pre>  </pre>
419  Of course, instead of using PCRE_DFA_RESTART, the same technique of re-running  Of course, instead of using PCRE_DFA_RESTART, the same technique of re-running
420  the entire match can also be used with <b>pcre_dfa_exec()</b>. Another  the entire match can also be used with the DFA matching functions. Another
421  possibility is to work with two buffers. If a partial match at offset <i>n</i>  possibility is to work with two buffers. If a partial match at offset <i>n</i>
422  in the first buffer is followed by "no match" when PCRE_DFA_RESTART is used on  in the first buffer is followed by "no match" when PCRE_DFA_RESTART is used on
423  the second buffer, you can then try a new match starting at offset <i>n+1</i> in  the second buffer, you can then try a new match starting at offset <i>n+1</i> in
# Line 436  Cambridge CB2 3QH, England. Line 434  Cambridge CB2 3QH, England.
434  </P>  </P>
435  <br><a name="SEC11" href="#TOC1">REVISION</a><br>  <br><a name="SEC11" href="#TOC1">REVISION</a><br>
436  <P>  <P>
437  Last updated: 26 August 2011  Last updated: 08 January 2012
438  <br>  <br>
439  Copyright &copy; 1997-2011 University of Cambridge.  Copyright &copy; 1997-2012 University of Cambridge.
440  <br>  <br>
441  <p>  <p>
442  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.868  
changed lines
  Added in v.869

  ViewVC Help
Powered by ViewVC 1.1.5