Re: preg_match() returns false but no documentation why
| From: | Jim Lucas | Date: | Wed, 30 May 2007 22:04:06 +0000 |
| Subject: | Re: preg_match() returns false but no documentation why | ||
| References: | 1 2 3 4 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-255881@lists.php.net to get a copy of this message | ||
Stut wrote:
Jared Farrish wrote:The op will need to use something other than forward slashes. so, this is going to match: ldap://testing123.com TRUE ldap://www.testing-123.com FALSE ldap://testing123.com.uk FALSE ldap://testing123.or.us TRUE preg_match('|^ldap(s)?://[a-zA-Z0-9-]+\.[a-zA-Z.]{2,5}$|', $this->server ) I also recommend using single quotes instead of double quotes here. btw: why is there a period in the second pattern? Also, why are you allowing for uppercase letters when the RFC's don't allow them? Just my thoughtsOn 5/30/07, Richard Lynch <ceo@l-i-e.com> wrote:preg_match("^ldap(s)?://[a-zA-Z0-9-]+\.[a-zA-Z.]{2,5}$",$this->server)On Wed, May 30, 2007 12:33 pm, Jared Farrish wrote:You need delimiters around the regex, as stated in the documentation. preg_match("/^ldap(s)?://[a-zA-Z0-9-]+\.[a-zA-Z.]{2,5}$/",$this->server) This isn't going to work, the op has two forward slashes in the string that he is wanting to match with.You are missing the start/end delimiters is your first problem...Which ones? I've got the starter "^" and the closer "$", so what else am I missing?
Although you don't need to use slashes, you can use any character you want but you must escape it in if it appears in the regex.-- Jim Lucas "Some men are born to greatness, some achieve greatness, and some have greatness thrust upon them." UnknownIt will return false on an error, such as not having matching delimiters aroung the regex. The error function may retuyrn 0, but which of the following constants is defined as 0? PREG_NO_ERROR PREG_INTERNAL_ERROR PREG_BACKTRACK_LIMIT_ERROR PREG_RECURSION_LIMIT_ERROR PREG_BAD_UTF8_ERROR -Stutwould a regex operation return false? It would return false if your string doesn't match the expression.The manual claims it will return a 0 signaling "0 matches found." And then, under "Return Values," it's says very quickly: "*preg_match()* returns *FALSE* if an error occurred." If it's not returning ANYTHING I'm assuming it's faulting, but the calling the error function returns 0 (kind've ironic, really...).