Re: Re: PHP regular expression
| From: | Michal Migurski | Date: | Fri, 12 Mar 2004 00:47:09 +0000 |
| Subject: | Re: Re: PHP regular expression | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-180225@lists.php.net to get a copy of this message | ||
>>>
>>> preg_match("/^([a-zA-Z0-9])+([.a-zA-Z0-9_-])*@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-]+)+[a-zA-Z0-9_-]$/",$email);
>>
>> The / characters are the regex delimiters. This is a throwback to the
>> Perl language. Basically, the / show where the beginning and end of the
>> regex is. You *MUST* have them. After the last / you can put modifiers
>> such as 'i' for case insensitive matching.
>>
>> You can also use other chars for delimiters, but I try to stick with /
>> for consistency.
>
>I think he meant.. the carrot after the delimiter which means NOT.. like
>/[^a]/ means match anything thats not an 'a'
In the case above, the caret means the beginning of a pattern. It only
negates a pattern in the "[]" context:
"/^a/" means an 'a' at the beginning of the pattern
"/[^a]/" means a char that is not an 'a'
"/^[^a]/" means a char that is not an 'a' at the beginning of a pattern
FYI, the O'reilly "Learning Perl" book has the best introduction to
perl regexp's I've seen yet; I still use it as an indispensable reference.
---------------------------------------------------------------------
michal migurski- contact info and pgp key:
sf/ca http://mike.teczno.com/contact.html