25.09.2014 Views

ZEND PHP 5 Certification STUDY GUIDE

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Strings And Patterns ” 91<br />

. Match any character<br />

ˆ Match the start of the string<br />

$ Match the end of the string<br />

\s Match any whitespace character<br />

\d Match any digit<br />

\w Match any “word” character<br />

Metacharacters can also be expressed using grouping expressions. For example, a<br />

series of valid alternatives for a character can be provided by using square brackets:<br />

/ab[cd]e/<br />

The expression above will match both abce and abde. You can also use other<br />

metacharacters, and provide ranges of valid characters inside a grouping expression:<br />

/ab[c-e\d]/<br />

This will match abc, abd, abe and any combination of ab followed by a digit.<br />

Quantifiers<br />

A quantifier allows you to specify the number of times a particular character or<br />

metacharacter can appear in a matched string. There are four types of quantifiers:<br />

* The character can appear zero or more times<br />

+ The character can appear one or more times<br />

? The character can appear zero or one times<br />

{n,m} The character can appear at least n times, and no more than m.<br />

Either parameter can be omitted to indicated a minimum limit<br />

with no maximum, or a maximum limit without a minimum, but<br />

not both.<br />

Licensed to 482634 - Amber Barrow (itsadmin@deakin.edu.au)<br />

Thus, for example, the expression ab?c matches both ac and abc, while ab{1,3}c<br />

matches abc, abbc and abbbc.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!