Re: regex operators

From: Date: Tue, 14 Oct 2003 16:50:39 +0000
Subject: Re: regex operators
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-4833@lists.php.net to get a copy of this message
* 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."

« previous php.internals (#4833) next »