Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:4860 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 92300 invoked by uid 1010); 15 Oct 2003 12:26:34 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 92255 invoked by uid 1007); 15 Oct 2003 12:26:33 -0000 Message-ID: <20031015122633.92254.qmail@pb1.pair.com> To: internals@lists.php.net References: <20031014165039.GP51024@bagend.shire> Date: Wed, 15 Oct 2003 15:35:16 +0300 Lines: 53 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4927.1200 X-MIMEOLE: Produced By Microsoft MimeOLE V5.50.4927.1200 X-Posted-By: 212.116.131.82 Subject: Re: [PHP-DEV] regex operators From: kouber@php.net ("Kouber Saparev") "Curt Zirzow" wrote in message news:20031014165039.GP51024@bagend.shire... > * Thus wrote David Sklar (sklar@sklar.com): > > 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!"; > > } > [...] > > > > 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? > > I'm thinking a more viable solution would be to do something like: > > mixed preg_match ( mixed pattern, string subject [, array matches [, int flags]]) > > if pattern is an array, preg_match will cycle through each one till > a match is made; returns the index of the array passed (that > matched) or false if not found. It's the same if you have the array with patterns and you make a simple foreach() cycle. I don't think that functions with internal loops should be created, when we have a clear solution without it. > > This should also be BC if you just pass one string. > > > Curt > -- > "I used to think I was indecisive, but now I'm not so sure."