Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:4833 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 9743 invoked by uid 1010); 14 Oct 2003 16:44:10 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 9655 invoked from network); 14 Oct 2003 16:44:08 -0000 Received: from unknown (HELO bagend.shire) (67.116.87.154) by pb1.pair.com with SMTP; 14 Oct 2003 16:44:08 -0000 Received: (qmail 697 invoked by uid 1000); 14 Oct 2003 16:50:39 -0000 Date: Tue, 14 Oct 2003 16:50:39 +0000 To: internals@lists.php.net Message-ID: <20031014165039.GP51024@bagend.shire> Mail-Followup-To: internals@lists.php.net References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.4.1i Subject: Re: [PHP-DEV] regex operators From: php-dev@zirzow.dyndns.org (Curt Zirzow) * 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. 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."