Re: preg_match() returns false but no documentation why
| From: | Jared Farrish | Date: | Wed, 30 May 2007 22:26:14 +0000 |
| Subject: | Re: preg_match() returns false but no documentation why | ||
| References: | 1 2 3 4 5 6 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-255883@lists.php.net to get a copy of this message | ||
On 5/30/07, Jim Lucas <lists@cmsws.com> wrote:
The op will need to use something other than forward slashes.You mean the delimiters (a la Richard's suggestion about using '|')? so, this is going to match:
Hmm. What makes them fail/not fail? The '//' in the pattern? preg_match('|^ldap(s)?://[a-zA-Z0-9-]+\.[a-zA-Z.]{2,5}$|', $this->server )ldap://testing123.com TRUE ldap://www.testing-123.com FALSE ldap://testing123.com.uk FALSE ldap://testing123.or.us TRUE
I also recommend using single quotes instead of double quotes here.Single Quotes: Noted. Any reason why? I guess you might be a little out of luck putting $vars into a regex without . concatenating.
why is there a period in the second pattern?The period comes from the original article on SitePoint (linked earlier). Is it unnecessary? I can't say I'm real sure what this means for the '.' in regex's: "Matches any single character except line break characters \r and \n. Most regex flavors have an option to make the dot match line break characters too." - http://www.regular-expressions.info/reference.html
Also, why are you allowing for uppercase letters when the RFC's don't allow them?I hadn't gotten far enough to strtolower(), but that's a good point, I hadn't actually considered it yet. Just my thoughts Hey, I appreciate it! -- Jared Farrish Intermediate Web Developer Denton, Tx Abraham Maslow: "If the only tool you have is a hammer, you tend to see every problem as a nail." $$