Online
 
Friday, 09 January 2009
 
 
More article:
Related Content:

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].

  • digit represents a digit between 09 (equivalent to [0-9]).

  • 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.

  • lower represents lowercase letters of the alphabet only.

  • upper represents uppercase letters of the alphabet only.

  • print represents all printable characters.

  • punct represents punctuation characters such as "." or ",".

  • space is the whitespace.

  • xdigit represents hexadecimal digits.

This makes it possible, for example, to rewrite our email validation regex as follows:

[[:alnum:]_]+@[[:alnum:]_]+\.[[:alnum:]_]{2,4}

Tags: Add more tags...,
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)

Comment an article
  Name
  E-mail
   Title
Available characters: 4000
 Notify me of follow-up comments
This image contains a scrambled text, it is using a combination of colors, font size, background, angle in order to disallow computer to automate reading. You will have to reproduce it to post on my homepage
Enter what you see:

No comment posted

Mobile Wallpaper 134
Statistic


Last Post

 
Top! Top!