| POSIX Regular Expressions |
| Article Index |
|---|
| POSIX Regular Expressions |
| Page 2 |
| Page 3 |
| Page 4 |
The regular expression standard that made its way through the POSIX standard is perhaps the simplest form of regex available to PHP programmers. As such, it makes a great learning tool because the functions that implement it do not provide any particular "advanced" features.
In addition to the standard rules that we have already discussed, the POSIX regex standard defines the concept of character classes as a way to make it even easier to specify character ranges. Character classes are always enclosed in a set of colon characters (:) and must be enclosed in square brackets. There are 12 character classes:
-
alpha represents a letter of the alphabet (either upper- or lowercase). This is equivalent to [A-Za-z].
-
alnum represents an alphanumeric character, just like [0-9A-Za-z].
-
blank represents "blank" characters, normally space and Tab.
-
cntrl represents "control" characters, such as DEL, INS, and so forth.
-
graph represents all the printable characters except the space.
This makes it possible, for example, to rewrite our email validation regex as follows:
[[:alnum:]_]+@[[:alnum:]_]+\.[[:alnum:]_]{2,4}
This entry was posted on . You can follow any responses to this entry through the RSS 2.0 feed.
You can leave a comment.
Tags: Simple PHP, Pear, Easy PHP, PHP Tutorial, PHP MySQL, XSLT, Sap Tutorial, CSS Tutorial, XSL FO Java, SQL Tutorial.
| Users' Comments (0) |
|
No comment posted








