32
32
the details differ between the two types of matching function. If both options
33
33
are set, PCRE_PARTIAL_HARD takes precedence.
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
39
PCRE_STUDY_JIT_PARTIAL_SOFT_COMPILE
40
PCRE_STUDY_JIT_PARTIAL_HARD_COMPILE
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.
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
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.
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.
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.
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.
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
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:
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.
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
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: