13.09.2016 Views

PHP and MySQL Web Development 4th Ed-tqw-_darksiderg

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Introducing Regular Expressions<br />

125<br />

matches "#at". If you want to limit this to a character between a <strong>and</strong> z, you can specify<br />

it as follows:<br />

[a-z]at<br />

Anything enclosed in the square brackets ([ <strong>and</strong> ]) is a character class—a set of characters<br />

to which a matched character must belong. Note that the expression in the square<br />

brackets matches only a single character.<br />

You can list a set; for example,<br />

[aeiou]<br />

means any vowel.<br />

You can also describe a range, as you just did using the special hyphen character, or a<br />

set of ranges, as follows:<br />

[a-zA-Z]<br />

This set of ranges st<strong>and</strong>s for any alphabetic character in upper- or lowercase.<br />

You can also use sets to specify that a character cannot be a member of a set. For<br />

example,<br />

[^a-z]<br />

matches any character that is not between a <strong>and</strong> z.The caret symbol (^) means not when<br />

it is placed inside the square brackets. It has another meaning when used outside square<br />

brackets, which we look at shortly.<br />

In addition to listing out sets <strong>and</strong> ranges, you can use a number of predefined character<br />

classes in a regular expression.These classes are shown in Table 4.3.<br />

Table 4.3<br />

Class<br />

Character Classes for Use in POSIX-Style Regular Expressions<br />

Matches<br />

[[:alnum:]]<br />

[[:alpha:]]<br />

[[:lower:]]<br />

[[:upper:]]<br />

[[:digit:]]<br />

[[:xdigit:]]<br />

[[:punct:]]<br />

[[:blank:]]<br />

[[:space:]]<br />

[[:cntrl:]]<br />

[[:print:]]<br />

[[:graph:]]<br />

Alphanumeric characters<br />

Alphabetic characters<br />

Lowercase letters<br />

Uppercase letters<br />

Decimal digits<br />

Hexadecimal digits<br />

Punctuation<br />

Tabs <strong>and</strong> spaces<br />

Whitespace characters<br />

Control characters<br />

All printable characters<br />

All printable characters except for space

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

Saved successfully!

Ooh no, something went wrong!