Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:99444 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 87430 invoked from network); 7 Jun 2017 20:13:38 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 7 Jun 2017 20:13:38 -0000 Authentication-Results: pb1.pair.com header.from=nikita.ppv@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=nikita.ppv@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.223.180 as permitted sender) X-PHP-List-Original-Sender: nikita.ppv@gmail.com X-Host-Fingerprint: 209.85.223.180 mail-io0-f180.google.com Received: from [209.85.223.180] ([209.85.223.180:36423] helo=mail-io0-f180.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id F6/B9-27119-27E58395 for ; Wed, 07 Jun 2017 16:13:38 -0400 Received: by mail-io0-f180.google.com with SMTP id y77so11864246ioe.3 for ; Wed, 07 Jun 2017 13:13:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=63AwP1/fjnRKdD8AA3A5AxMy82P/UQ8LTzNXR3zbkGY=; b=dmjOE206l+sjD+bB6Z2xyyj98Y1IfPpOY0NlwAkmm48/mWa4VwxKhdofP8lCvXcurE zK0Okkkcy4p2DRo4zuZBjAP8fAFUTjZ+uAyms7uJDPjBMd93LrOj/PK9rGn1SRaWLiPF w2eN4gIoQFW+ygVfX3bqrgvJIFzt/jiPf5IuO6ZNonJJe28G+Immgk3AFQ6zZ04z7nzk +s23zxAAGJUq0el9u3I/29Ps9eZaZsbkdA0OJN3bzSbudDjdvI+urhHGJ+IVd0GqWVp+ 2N1RPVMU+8o1FpeB83tW4bcoCgFW17/eNDPo5hksomX5b22nivB10F3WuVSD9QFPL21w fk5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=63AwP1/fjnRKdD8AA3A5AxMy82P/UQ8LTzNXR3zbkGY=; b=kMshufl1Tqi5KPJmB0HXtYFWZzs+sTr+Q0WPHbyPWCwfiNEgNX5yL17DjL6bCFh4i5 m2/S6U8KqRSYzu1xc+7ryVzh6fKys5jRKcwkbVg0S4deMNEFsPc5+4l/EKnvy15LirQ4 CkjOCe6DdaH914pn/pfSdxEhhaPququcqZjF19YnM6WxRoupp7SXYyAGjw64waBLNDJF 54EoPKwb2FX5Ti+rY4bdY0oPxfoNDsFBBrA3OmoitNAdM/VT4yv9zl5M87pImNcjJvMM mFyQSrpQkmajZDoppb6WQdqDtycHphoTsgVyk/U7a2Nt6nM43vgdLUWAC8WCLtV7BVOm xmjw== X-Gm-Message-State: AODbwcDkM8bQ6nK4OSGdsSVlDr2YwaPLDEM7sD4mbasGOWIQQFxx7Zqe eIJVxQtEEogAIsSxFdii1nmlC7E6tw== X-Received: by 10.107.12.144 with SMTP id 16mr15687683iom.150.1496866415362; Wed, 07 Jun 2017 13:13:35 -0700 (PDT) MIME-Version: 1.0 Received: by 10.107.12.158 with HTTP; Wed, 7 Jun 2017 13:13:34 -0700 (PDT) In-Reply-To: References: Date: Wed, 7 Jun 2017 22:13:34 +0200 Message-ID: To: Rasmus Schultz Cc: PHP internals Content-Type: multipart/alternative; boundary="001a113ee16af6e1430551645e85" Subject: Re: [PHP-DEV] preg_match() option for anchored offset? From: nikita.ppv@gmail.com (Nikita Popov) --001a113ee16af6e1430551645e85 Content-Type: text/plain; charset="UTF-8" On Wed, Jun 7, 2017 at 10:03 PM, 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? > You are looking for the \G anchor or the A modifier. Nikita --001a113ee16af6e1430551645e85--