~ubuntu-branches/ubuntu/trusty/pcre3/trusty

« back to all changes in this revision

Viewing changes to doc/html/pcrepartial.html

  • Committer: Package Import Robot
  • Author(s): Mark Baker
  • Date: 2012-09-13 19:58:45 UTC
  • mfrom: (23.1.11 sid)
  • Revision ID: package-import@ubuntu.com-20120913195845-wd12z63sm0b07n59
Tags: 1:8.31-1
* New upstream release
* Applied patch from upstream bugzilla #1287 to fix bug where wrong
  value is in re_nsub in some cases (Closes: #686495)

Show diffs side-by-side

added added

removed removed

Lines of Context:
58
58
are set, PCRE_PARTIAL_HARD takes precedence.
59
59
</P>
60
60
<P>
61
 
Setting a partial matching option disables the use of any just-in-time code
62
 
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
 
61
If you want to use partial matching with just-in-time optimized code, you must
 
62
call <b>pcre_study()</b> or <b>pcre16_study()</b> with one or both of these
 
63
options:
 
64
<pre>
 
65
  PCRE_STUDY_JIT_PARTIAL_SOFT_COMPILE
 
66
  PCRE_STUDY_JIT_PARTIAL_HARD_COMPILE
 
67
</pre>
 
68
PCRE_STUDY_JIT_COMPILE should also be set if you are going to run non-partial
 
69
matches on the same pattern. If the appropriate JIT study mode has not been set
 
70
for a match, the interpretive matching code is used.
 
71
</P>
 
72
<P>
 
73
Setting a partial matching option disables two of PCRE's standard
64
74
optimizations. PCRE remembers the last literal data unit in a pattern, and
65
75
abandons matching immediately if it is not present in the subject string. This
66
76
optimization cannot be used for a subject string that might match only
317
327
</pre>
318
328
At this stage, an application could discard the text preceding "23ja", add on
319
329
text from the next segment, and call the matching function again. Unlike the
320
 
DFA matching functions the entire matching string must always be available, and
321
 
the complete matching process occurs for each call, so more memory and more
 
330
DFA matching functions, the entire matching string must always be available,
 
331
and the complete matching process occurs for each call, so more memory and more
322
332
processing time is needed.
323
333
</P>
324
334
<P>
326
336
with \b or \B, the string that is returned for a partial match includes
327
337
characters that precede the partially matched string itself, because these must
328
338
be retained when adding on more characters for a subsequent matching attempt.
 
339
However, in some cases you may need to retain even earlier characters, as
 
340
discussed in the next section.
329
341
</P>
330
342
<br><a name="SEC9" href="#TOC1">ISSUES WITH MULTI-SEGMENT MATCHING</a><br>
331
343
<P>
340
352
includes the effect of PCRE_NOTEOL.
341
353
</P>
342
354
<P>
343
 
2. Lookbehind assertions at the start of a pattern are catered for in the
344
 
offsets that are returned for a partial match. However, in theory, a lookbehind
345
 
assertion later in the pattern could require even earlier characters to be
346
 
inspected, and it might not have been reached when a partial match occurs. This
347
 
is probably an extremely unlikely case; you could guard against it to a certain
348
 
extent by always including extra characters at the start.
349
 
</P>
350
 
<P>
351
 
3. Matching a subject string that is split into multiple segments may not
 
355
2. Lookbehind assertions that have already been obeyed are catered for in the
 
356
offsets that are returned for a partial match. However a lookbehind assertion
 
357
later in the pattern could require even earlier characters to be inspected. You
 
358
can handle this case by using the PCRE_INFO_MAXLOOKBEHIND option of the
 
359
<b>pcre_fullinfo()</b> or <b>pcre16_fullinfo()</b> functions to obtain the length
 
360
of the largest lookbehind in the pattern. This length is given in characters,
 
361
not bytes. If you always retain at least that many characters before the
 
362
partially matched string, all should be well. (Of course, near the start of the
 
363
subject, fewer characters may be present; in that case all characters should be
 
364
retained.)
 
365
</P>
 
366
<P>
 
367
3. Because a partial match must always contain at least one character, what
 
368
might be considered a partial match of an empty string actually gives a "no
 
369
match" result. For example:
 
370
<pre>
 
371
    re&#62; /c(?&#60;=abc)x/
 
372
  data&#62; ab\P
 
373
  No match
 
374
</pre>
 
375
If the next segment begins "cx", a match should be found, but this will only
 
376
happen if characters from the previous segment are retained. For this reason, a
 
377
"no match" result should be interpreted as "partial match of an empty string"
 
378
when the pattern contains lookbehinds.
 
379
</P>
 
380
<P>
 
381
4. Matching a subject string that is split into multiple segments may not
352
382
always produce exactly the same result as matching over one single long string,
353
383
especially when PCRE_PARTIAL_SOFT is used. The section "Partial Matching and
354
384
Word Boundaries" above describes an issue that arises if the pattern ends with
390
420
  data&#62; gsb\R\P\P\D
391
421
  Partial match: gsb
392
422
</pre>
393
 
4. Patterns that contain alternatives at the top level which do not all start
 
423
5. Patterns that contain alternatives at the top level which do not all start
394
424
with the same pattern item may not work as expected when PCRE_DFA_RESTART is
395
425
used. For example, consider this pattern:
396
426
<pre>
435
465
</P>
436
466
<br><a name="SEC11" href="#TOC1">REVISION</a><br>
437
467
<P>
438
 
Last updated: 21 January 2012
 
468
Last updated: 24 February 2012
439
469
<br>
440
470
Copyright &copy; 1997-2012 University of Cambridge.
441
471
<br>