Learning PHP Home
http://us2.php.net/manual/en/regexp.reference.meta.php
http://seeds4c.org/Regular+expressions
OperatorDescription
^The circumflex symbol marks the beginning of a pattern, although in some cases it can be omitted
$Same as with the circumflex symbol, the dollar sign marks the end of a search pattern
.The period matches any single character
?It will match the preceding pattern zero or one times
+It will match the preceding pattern one or more times
*It will match the preceding pattern zero or more times
|Boolean OR
-Matches a range of elements
()Groups a different pattern elements together
[]Matches any single character between the square brackets
{min, max}It is used to match exact character counts
\dMatches any single digit
\DMatches any single non digit caharcter
\wMatches any alpha numeric character including underscore (_)
\WMatches any non alpha numeric character excluding the underscore character
\sMatches whitespace character

As an addition in PHP the forward slash character is escaped using the simple slash \. Example: ‘/he\/llo/’

To have a brief understanding how these operators are used, let’s have a look at a few examples:

ExampleDescription
‘/hello/’It will match the word hello
‘/^hello/’It will match hello at the start of a string. Possible matches are hello or helloworld, but not worldhello
‘/hello$/’It will match hello at the end of a string.
‘/he.o/’It will match any character between he and o. Possible matches are helo or heyo, but not hello
‘/he?llo/’It will match either llo or hello
‘/hello+/’It will match hello on or more time. E.g. hello or hellohello
‘/he*llo/’Matches llo, hello or hehello, but not hellooo
‘/hello|world/’It will either match the word hello or world
‘/(A-Z)/’Using it with the hyphen character, this pattern will match every uppercase character from A to Z. E.g. A, B, C…
‘/[abc]/’It will match any single character a, b or c
‘/abc{1}/’Matches precisely one c character after the characters ab. E.g. matches abc, but not abcc
‘/abc{1,}/’Matches one or more c character after the characters ab. E.g. matches abc or abcc
‘/abc{2,4}/’Matches between two and four c character after the characters ab. E.g. matches abcc, abccc or abcccc, but not abc