note 87844 added to function.preg-match
| From: | Pete at osu1 dot php dot net | Date: | Fri, 26 Dec 2008 07:37:39 +0000 |
| Subject: | note 87844 added to function.preg-match | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-148513@lists.php.net to get a copy of this message | ||
Can you believe it, right after I posted my last comment I figured it out, usually happens.
Help to any newbies that struggle with it:
using:
preg_match(/^[a-zA-Z]+[^0-9]/', $string);
means match characters a up to z at beggining and through the string, dont match 0 to 9, but for
some reason it will ignore this 'dont match' 0-9 because there is no ending expression. So
as long as there are characters a-z even if there are digits it will still return true.
To get past this, you must declare what you want matching at the end of the string i.e:
preg_match(/^[a-zA-Z]+[^0-9][a-zA-Z]+$/', $string);
Notice that extra expression at the end with the $ sign stating that last expression must match at
the end of the string. So now it reads, if first character is a-z and there is not 0-9 and end
character is a-z return true.
----
Server IP: 87.124.35.190
Probable Submitter: 80.6.32.196
----
Manual Page -- http://www.php.net/manual/en/function.preg-match.php
Edit -- https://master.php.net/note/edit/87844
Del: integrated -- https://master.php.net/note/delete/87844/integrated
Del: useless -- https://master.php.net/note/delete/87844/useless
Del: bad code -- https://master.php.net/note/delete/87844/bad+code
Del: spam -- https://master.php.net/note/delete/87844/spam
Del: non-english -- https://master.php.net/note/delete/87844/non-english
Del: in docs -- https://master.php.net/note/delete/87844/in+docs
Del: other reasons-- https://master.php.net/note/delete/87844
Reject -- https://master.php.net/note/reject/87844
Search -- https://master.php.net/manage/user-notes.php