Req #77744 [Opn]: Add preg_match flag to return only offsets
| From: | nikic@php.net | Date: | Thu, 21 Mar 2019 11:36:18 +0000 |
| Subject: | Req #77744 [Opn]: Add preg_match flag to return only offsets | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-220112@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=77744&edit=1
ID: 77744
Updated by: nikic@php.net
Reported by: cananian at wikimedia dot org
Summary: Add preg_match flag to return only offsets
Status: Open
Type: Feature/Change Request
Package: PCRE related
PHP Version: 7.3.3
-Assigned To:
+Assigned To: nikic
Block user comment: N
Private report: N
New Comment:
PR: https://github.com/php/php-src/pull/3971
Previous Comments:
------------------------------------------------------------------------
[2019-03-18 16:17:30] nikic@php.net
Related To: Bug #32458
------------------------------------------------------------------------
[2019-03-14 18:39:18] cananian at wikimedia dot org
Description:
------------
When creating a high-performance lexer (for example, an HTML5 parser), it is worthwhile to try to
avoid the number of string copies made. You can perform matches using offsets into your master
source string. However, preg_match will copy a substring for the entire matched region
($matches[0]) as well as for all captured patterns. This can get expensive if the matched
region/captured patterns are very large.
It would be helpful if PHP's preg_match* functions offered a flag, say PREG_LENGTH_CAPTURE,
which returned the numeric length instead of the string. In combination,
PREG_OFFSET_CAPTURE|PREG_LENGTH_CAPTURE would return the numeric length in element 0 and the offset
in element 1, and avoid the need to copy the matched substring unnecessarily.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=77744&edit=1