Req #77459 [NEW]: Add partial match support to preg_match
| From: | paul dot crovella at gmail dot com | Date: | Tue, 15 Jan 2019 08:53:18 +0000 |
| Subject: | Req #77459 [NEW]: Add partial match support to preg_match | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-218951@lists.php.net to get a copy of this message | ||
From: paul dot crovella at gmail dot com
Operating system:
PHP version: Next Minor Version
Package: PCRE related
Bug Type: Feature/Change Request
Bug description:Add partial match support to preg_match
Description:
------------
Please add support for PCRE2 partial matching[1] to preg_match.
A partial match is one that occurs when a subject matches a regex as far
as it goes but ends before a full match, or sure failure to match, can
be determined. The regex /abc/ would normally fail to match 'ab', but
with one of the partial flags given (see below) it'd instead return a
partial match. This is useful to indicate that more data needs to be
read into a buffer before trying the match again. (See: multi-segment
matching[2].)
I imagine this would come about as PREG_PARTIAL_SOFT and
PREG_PARTIAL_HARD flags (neither on by default) corresponding to
PCRE2_PARTIAL_SOFT and PCRE2_PARTIAL_HARD, respectively, which would
pass through as options to pcre2_match and pcre2_jit_match.
pcre2_jit_compile would get PCRE2_JIT_PARTIAL_SOFT or
PCRE2_JIT_PARTIAL_HARD as appropriate in addition to the usual
PCRE2_JIT_COMPLETE.
When a partial match is found preg_match should return a new value (2?)
in order to distinguish it, and the $matches array (if given) should be
filled with a single member consisting of the string participating in
partial match (and possibly a little more.) This should be from the
beginning of the matched data minus the length of the longest
lookbehind* through to the end of the subject string. For example:
/baz(?<=barbaz)(?=quux)/
applied to:
abcfoobarbazqu
should result in foobarbazqu in the $matches array. This ensures enough
of the string is kept for further match attempts to have a chance to
succeed. (Fortunately PCRE ignores \K in a partial match, so there's no
need to worry about it.) Another option that comes to mind would be to
just give the offset of this substring and let the user chop it off or
pass it as the offset argument of preg_match as desired.
---
* Available from pcre2_pattern_info given PCRE2_INFO_MAXLOOKBEHIND. See
[3] for details.
[1] https://www.pcre.org/current/doc/html/pcre2partial.html
[2] https://www.pcre.org/current/doc/html/pcre2partial.html#SEC7
[3] https://www.pcre.org/current/doc/html/pcre2partial.html#SEC8
--
Edit bug report at https://bugs.php.net/bug.php?id=77459&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=77459&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=77459&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=77459&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=77459&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=77459&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=77459&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=77459&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=77459&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=77459&r=support
Expected behavior: https://bugs.php.net/fix.php?id=77459&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=77459&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=77459&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=77459&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=77459&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=77459&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=77459&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=77459&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=77459&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=77459&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=77459&r=mysqlcfg