Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:99450 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 25762 invoked from network); 8 Jun 2017 07:10:38 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 8 Jun 2017 07:10:38 -0000 Authentication-Results: pb1.pair.com smtp.mail=rasmus@mindplay.dk; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=rasmus@mindplay.dk; sender-id=unknown Received-SPF: error (pb1.pair.com: domain mindplay.dk from 209.85.192.176 cause and error) X-PHP-List-Original-Sender: rasmus@mindplay.dk X-Host-Fingerprint: 209.85.192.176 mail-pf0-f176.google.com Received: from [209.85.192.176] ([209.85.192.176:35444] helo=mail-pf0-f176.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 2A/2D-27119-C68F8395 for ; Thu, 08 Jun 2017 03:10:37 -0400 Received: by mail-pf0-f176.google.com with SMTP id l89so14041260pfi.2 for ; Thu, 08 Jun 2017 00:10:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mindplay-dk.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=0/hHC4LkpF1ZnxoDFvXCRwki10b3G0KGq6WcxwUMnb8=; b=HQRvwFU97jxwKl4qtETDVYzy1JD2U2cqjDolkhyuiAjfT4hbPvd10J1KRBZ/XA5aGO LF3hbbU5ThYYAx6rG4rJEr4g2XUNdelUqlPTmhTaSKG5Hgh9NBgT6i/63dBscfDz/KzQ yr0nZ8KX1H8Fdi204jsTMUKJ74EQCcAndKXJD82zelywcT9V+mcDphYjqiXb0A+jKm4t EhtBP+cYtaGbzTv62RV3OHeQZvGic56aorGaE5duG3jZkt918d2zQUnisJi3/kIJDCSV 3VP9ao0keSuq4bKiNtS7cFQ2NnshSSdVVJ6pbZIRXIpGK0xQSoJfSaBpALdBnBT2ysE9 eJ/Q== 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=0/hHC4LkpF1ZnxoDFvXCRwki10b3G0KGq6WcxwUMnb8=; b=lGNblsHZuQLO3uYyuYOt/NdbAZa81gsmVFcnRXhOcEz6dWRxNwlqTOyJY8BHfampZc 2cvY7vI0vcosT1QqJfu3bPqEW90gdZTYfMfWFJUkagdrZ3QaJ9NJlwsotTwbLTWrZh3l Gc97yYhnVmdCPI7X5CfikF3UH0UE+8QF71lNGyPFMG6w5Dtq/ynMr/yjT8bsh1iiDAug BvJopvYSI+59AGPSLjMZdFAE3NrY18Gt4dZi/Oisgu0J0s1ijJbt+D11hwI2GdZNyJGZ KSr23kmhTIbNSDy06LHNONzeapx9Am6K1aa5TWEWMAYYCSZ7U9bOnoFUbZQMqJgzN/vh UA9g== X-Gm-Message-State: AODbwcDPTxuYseRpcrjXDdlAbe8MvOIb4FuZtAxpXzoi6yAm51iiVcoV 7Cw6vryWPFU31Yy9/m+vreKozLSjkd1g X-Received: by 10.99.127.19 with SMTP id a19mr36780304pgd.213.1496905833426; Thu, 08 Jun 2017 00:10:33 -0700 (PDT) MIME-Version: 1.0 Received: by 10.100.131.23 with HTTP; Thu, 8 Jun 2017 00:10:33 -0700 (PDT) In-Reply-To: References: Date: Thu, 8 Jun 2017 09:10:33 +0200 Message-ID: To: Nikita Popov Cc: PHP internals Content-Type: multipart/alternative; boundary="94eb2c1b592e76d2e305516d8ca6" Subject: Re: [PHP-DEV] preg_match() option for anchored offset? From: rasmus@mindplay.dk (Rasmus Schultz) --94eb2c1b592e76d2e305516d8ca6 Content-Type: text/plain; charset="UTF-8" > You are looking for the \G anchor or the A modifier. Both of these options work great! I've submitted a patch to the manual page with a note explaining these options. Thanks :-) On Wed, Jun 7, 2017 at 10:13 PM, Nikita Popov wrote: > 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 > > --94eb2c1b592e76d2e305516d8ca6--