Re: regex operators
| From: | Kouber Saparev | Date: | Wed, 15 Oct 2003 12:35:16 +0000 |
| Subject: | Re: regex operators | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-4860@lists.php.net to get a copy of this message | ||
"Curt Zirzow" <php-dev@zirzow.dyndns.org> 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."