Re: regex operators
| From: | netcat | Date: | Tue, 14 Oct 2003 18:24:50 +0000 |
| Subject: | Re: regex operators | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-4842@lists.php.net to get a copy of this message | ||
Hartmut Holzgraefe wrote:
David Sklar wrote:seems the sanest thing up until now. slighly O.T.: would be and even better if lambda functions were available hereI 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})?$/':i've started to play with a more general way to handle this: switch(mixed data [, callback compare_function])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!";}
{-- NetCat -------------------------------------------------------- FREE 10MB email + Antivirus + AntiSpam + POP3 + more.... Get it at http://www.doal.co.il:81/free/?c=both..."compare_function" would default to the functionality of the "==" operator to show the current behavior "compare_function" will be called with two parameters: the switch expression and the case value and should return true if both match, false otherwise as a special case "compare_function" should also accept "===" this way we do not have to add new keywords and are not limited to preg expresions here, possible uses not possible now would include: switch($foobar, "===") { case false: ... case 0: ... case '': ... switch($foobar, "preg_match") { case '/^\d{5}$/': ... case '/(foo)?bar/': ... switch($foobar, "fnmatch") { case '*.gif': ... case '*.jpg': ... switch($foober, "my_custom_function") { ... switch($foobar, array($this, "compare_function") { ...