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

« back to all changes in this revision

Viewing changes to doc/pcrepartial.3

  • 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:
1
 
.TH PCREPARTIAL 3
 
1
.TH PCREPARTIAL 3 "24 February 2012" "PCRE 8.31"
2
2
.SH NAME
3
3
PCRE - Perl-compatible regular expressions
4
4
.SH "PARTIAL MATCHING IN PCRE"
32
32
the details differ between the two types of matching function. If both options
33
33
are set, PCRE_PARTIAL_HARD takes precedence.
34
34
.P
35
 
Setting a partial matching option disables the use of any just-in-time code
36
 
that was set up by studying the compiled pattern with the
37
 
PCRE_STUDY_JIT_COMPILE option. It also disables two of PCRE's standard
 
35
If you want to use partial matching with just-in-time optimized code, you must
 
36
call \fBpcre_study()\fP or \fBpcre16_study()\fP with one or both of these
 
37
options:
 
38
.sp
 
39
  PCRE_STUDY_JIT_PARTIAL_SOFT_COMPILE
 
40
  PCRE_STUDY_JIT_PARTIAL_HARD_COMPILE
 
41
.sp
 
42
PCRE_STUDY_JIT_COMPILE should also be set if you are going to run non-partial
 
43
matches on the same pattern. If the appropriate JIT study mode has not been set
 
44
for a match, the interpretive matching code is used.
 
45
.P
 
46
Setting a partial matching option disables two of PCRE's standard
38
47
optimizations. PCRE remembers the last literal data unit in a pattern, and
39
48
abandons matching immediately if it is not present in the subject string. This
40
49
optimization cannot be used for a subject string that might match only
293
302
.sp
294
303
At this stage, an application could discard the text preceding "23ja", add on
295
304
text from the next segment, and call the matching function again. Unlike the
296
 
DFA matching functions the entire matching string must always be available, and
297
 
the complete matching process occurs for each call, so more memory and more
 
305
DFA matching functions, the entire matching string must always be available,
 
306
and the complete matching process occurs for each call, so more memory and more
298
307
processing time is needed.
299
308
.P
300
309
\fBNote:\fP If the pattern contains lookbehind assertions, or \eK, or starts
301
310
with \eb or \eB, the string that is returned for a partial match includes
302
311
characters that precede the partially matched string itself, because these must
303
312
be retained when adding on more characters for a subsequent matching attempt.
 
313
However, in some cases you may need to retain even earlier characters, as
 
314
discussed in the next section.
304
315
.
305
316
.
306
317
.SH "ISSUES WITH MULTI-SEGMENT MATCHING"
315
326
doing multi-segment matching you should be using PCRE_PARTIAL_HARD, which
316
327
includes the effect of PCRE_NOTEOL.
317
328
.P
318
 
2. Lookbehind assertions at the start of a pattern are catered for in the
319
 
offsets that are returned for a partial match. However, in theory, a lookbehind
320
 
assertion later in the pattern could require even earlier characters to be
321
 
inspected, and it might not have been reached when a partial match occurs. This
322
 
is probably an extremely unlikely case; you could guard against it to a certain
323
 
extent by always including extra characters at the start.
324
 
.P
325
 
3. Matching a subject string that is split into multiple segments may not
 
329
2. Lookbehind assertions that have already been obeyed are catered for in the
 
330
offsets that are returned for a partial match. However a lookbehind assertion
 
331
later in the pattern could require even earlier characters to be inspected. You
 
332
can handle this case by using the PCRE_INFO_MAXLOOKBEHIND option of the
 
333
\fBpcre_fullinfo()\fP or \fBpcre16_fullinfo()\fP functions to obtain the length
 
334
of the largest lookbehind in the pattern. This length is given in characters,
 
335
not bytes. If you always retain at least that many characters before the
 
336
partially matched string, all should be well. (Of course, near the start of the
 
337
subject, fewer characters may be present; in that case all characters should be
 
338
retained.)
 
339
.P
 
340
3. Because a partial match must always contain at least one character, what
 
341
might be considered a partial match of an empty string actually gives a "no
 
342
match" result. For example:
 
343
.sp
 
344
    re> /c(?<=abc)x/
 
345
  data> ab\eP
 
346
  No match
 
347
.sp
 
348
If the next segment begins "cx", a match should be found, but this will only
 
349
happen if characters from the previous segment are retained. For this reason, a
 
350
"no match" result should be interpreted as "partial match of an empty string"
 
351
when the pattern contains lookbehinds.
 
352
.P
 
353
4. Matching a subject string that is split into multiple segments may not
326
354
always produce exactly the same result as matching over one single long string,
327
355
especially when PCRE_PARTIAL_SOFT is used. The section "Partial Matching and
328
356
Word Boundaries" above describes an issue that arises if the pattern ends with
363
391
  data> gsb\eR\eP\eP\eD
364
392
  Partial match: gsb
365
393
.sp
366
 
4. Patterns that contain alternatives at the top level which do not all start
 
394
5. Patterns that contain alternatives at the top level which do not all start
367
395
with the same pattern item may not work as expected when PCRE_DFA_RESTART is
368
396
used. For example, consider this pattern:
369
397
.sp
412
440
.rs
413
441
.sp
414
442
.nf
415
 
Last updated: 21 January 2012
 
443
Last updated: 24 February 2012
416
444
Copyright (c) 1997-2012 University of Cambridge.
417
445
.fi