05.05.2013 Views

Programming PHP

Programming PHP

Programming PHP

SHOW MORE
SHOW LESS

Create successful ePaper yourself

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

Table 4-7. POSIX character classes (continued)<br />

Class Description Expansion<br />

[:ascii:] 7-bit ASCII [\x01-\x7F]<br />

[:blank:] Horizontal whitespace (space, tab) [ \t]<br />

[:cntrl:] Control characters [\x01-\x1F]<br />

[:digit:] Digits [0-9]<br />

[:graph:] Characters that use ink to print (non-space,<br />

non-control)<br />

[^\x01-\x20]<br />

[:lower:] Lowercase letter [a-z]<br />

[:print:] Printable character (graph class plus space and<br />

tab)<br />

[\t\x20-\xFF]<br />

[:punct:] Any punctuation character, such as the period (.)<br />

and the semicolon (;)<br />

[-!"#$%&'( )*+,./:;?@[\\]^_`{|}~]<br />

[:space:] Whitespace (newline, carriage return, tab, space,<br />

vertical tab)<br />

[\n\r\t \x0B]<br />

[:upper:] Uppercase letter [A-Z]<br />

[:xdigit:] Hexadecimal digit [0-9a-fA-F]<br />

Each [:something:] class can be used in place of a character in a character class. For<br />

instance, to find any character that’s a digit, an uppercase letter, or an at sign (@), use<br />

the following regular expression:<br />

[@[:digit:][:upper:]]<br />

However, you can’t use a character class as the endpoint of a range:<br />

ereg('[A-[:lower:]]', 'string'); // invalid regular expression<br />

Some locales consider certain character sequences as if they were a single character—<br />

these are called collating sequences. To match one of these multicharacter sequences<br />

in a character class, enclose it with [. and .]. For example, if your locale has the collating<br />

sequence ch, you can match s, t, or ch with this character class:<br />

[st[.ch.]]<br />

The final POSIX extension to character classes is the equivalence class, specified by<br />

enclosing the character in [= and =]. Equivalence classes match characters that have<br />

the same collating order, as defined in the current locale. For example, a locale may<br />

define a, á, and ä as having the same sorting precedence. To match any one of them,<br />

the equivalence class is [=a=].<br />

Anchors<br />

An anchor limits a match to a particular location in the string (anchors do not match<br />

actual characters in the target string). Table 4-8 lists the anchors supported by<br />

POSIX regular expressions.<br />

100 | Chapter 4: Strings<br />

This is the Title of the Book, eMatter Edition<br />

Copyright © 2002 O’Reilly & Associates, Inc. All rights reserved.

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

Saved successfully!

Ooh no, something went wrong!