Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:4826 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 29018 invoked by uid 1010); 14 Oct 2003 14:55:09 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 28992 invoked from network); 14 Oct 2003 14:55:09 -0000 Received: from unknown (HELO stella.fastforwardnetwork.com) (209.51.153.50) by pb1.pair.com with SMTP; 14 Oct 2003 14:55:09 -0000 Received: (qmail 1317 invoked from network); 14 Oct 2003 14:57:58 -0000 Received: from pd9e61342.dip.t-dialin.net (HELO hristov.com) (217.230.19.66) by d.goto.bg with SMTP; 14 Oct 2003 14:57:58 -0000 Message-ID: <3F8C0EFC.6010108@hristov.com> Date: Tue, 14 Oct 2003 17:58:04 +0300 User-Agent: Mozilla/5.0 (X11; U; Linux i586; en-US; rv:1.5) Gecko/20030917 X-Accept-Language: en-us, en MIME-Version: 1.0 To: David Sklar CC: internals@lists.php.net References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] regex operators From: php@hristov.com (Andrey Hristov) Hi David, 2 weeks ago Hartmut Holzgraefe had similar idea : switch ($data, "preg_match") { case '/foo.*?bar/i' : /* computation here */ break; } The second argument is a callback. Andrey David Sklar wrote: >I was thinking about adding one or two regex-related features to the engine: > >1. "preg_case": this would behave just like case but instead of doing an >equality comparison, would match against a regular expression, e.g. > >switch($data) { > preg_case '/^\d{5}(-\d{4})?$/': > print "US Postal Code"; > break; > preg_case '/^[a-z]\d[a-z] ?\d[a-z]\d$/i'; > print "Canadian Postal Code"; > break; > default: > print "something else!"; >} > >Where should any captured subpatterns go? > >2. A regex match operator that returns an array containing subpatterns. If >there is no match against the regex, then an empty array (or just false?) >would be returned. > >if ($data =~ '/^(\d{5})(-\d{4})?$/') { > print "The whole postal code is $data[0]."; > print "The first five digits is $data[1]."; > if ($data[2]) { print "The ZIP+4 is $data[2].";} >} > >Some issues with adding these features: > >- It creates an engine dependency on the PCRE library. >- There would have to be some new opcodes and parser tokens >- Ideally the code that implements these operators could share as much as >possible with what's already been done in the PCRE extension -- is that >possible? > >Comments? > >Thanks, >David > > >