On 07/06/2017 21:03, Rasmus Schultz wrote:
What do you think about adding another option to preg_match() to allow the
$offset parameter to be treated as the start anchor?

The manual proposes to do this:

     $subject = "abcdef";
     $pattern = '/^def/';
     $offset = 3;
     preg_match($pattern, substr($subject, $offset), $matches);

In other words, use substr() to copy the entire remainder of the string.

I just wrote a simple SQL parser tonight, and had to use this approach,
which (I imagine) must be pretty inefficient?

I'd like to be able to do the following:

     $subject = "abcdef";
     $pattern = '/^def/';
     $offset = 3;
     preg_match($pattern, $subject, $matches, PREG_ANCHOR_OFFSET, $offset);

This new option would make the ^ anchor work from the given $offset, which
allows me to parse the entire $subject without copying anything.

Thoughts?


How would you propose to implement this? Is it something PCRE already supports? Or would you manipulate the subject string pointer at the point it's passed down? The latter approach seems doable, but I'm not sure if there are any subtle gotchas.

Regards,

--
Rowan Collins
[IMSoP]


--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to