58
58
are set, PCRE_PARTIAL_HARD takes precedence.
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
65
PCRE_STUDY_JIT_PARTIAL_SOFT_COMPILE
66
PCRE_STUDY_JIT_PARTIAL_HARD_COMPILE
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.
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
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.
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.
330
342
<br><a name="SEC9" href="#TOC1">ISSUES WITH MULTI-SEGMENT MATCHING</a><br>
340
352
includes the effect of PCRE_NOTEOL.
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.
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
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:
371
re> /c(?<=abc)x/
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.
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> gsb\R\P\P\D
391
421
Partial match: gsb
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: