PHP Regular Expression special character [: alnum:] [: alpha:], etc.

Source: Internet
Author: User
Tags ereg php regular expression printable characters alphanumeric characters

If "^" is displayed in "[]", this expression does not match the characters in, for example, "/[^ a-z]/" does not match any lower-case letters! The regular expression provides the following default values:

'[: Alnum:]' matches any letter
Alphanumeric characters: '[: alpha:]' and '[: digit:]'.

'[: Alpha:]' matches any letter or number
Alphabetic characters: '[: lower:]' and '[: upper:]'.

'[: Blank:]'
Blank characters: space and tab.

'[: Cntrl:]'
Control characters. In ASCII, these characters have octal codes 000 through 037, and 177 ('del '). In other character sets, these are the equivalent characters, if any.

'[: Digit:]' matches any number
Digits: '0 1 2 3 4 5 6 7 8 9 '.

'[: Graph:]'
Graphical characters: '[: alnum:]' and '[: punct:]'.

'[: Lower:]' matches any lowercase letter
Lower-case letters: 'a B c d e f g h I j k l m n o p q r s t u v w
X y Z '.
'[: Print:]'
Printable characters: '[: alnum:]', '[: punct:]', and space.

'[: Punct:]' matches any punctuation marks
Punctuation characters :'! "# $ % & '() * +,-./:; <=>? @ [\] ^ _ '{| }~ '.

'[: Space:]' matches the space character
Space characters: tab, newline, vertical tab, form feed, carriage
Return, and space.

'[: Upper:]' matches any uppercase letter
Upper-case letters: 'a B C D E F G H I J K L M N O P Q R S T U V W
X y Z '.

'[: Xdigit:]' matches any hexadecimal number
Hexadecimal digits: '0 1 2 3 4 5 6 7 8 9 a B c d e f a B c d e F '.

For example, '[[: alnum:]' means '[0-9A-Za-z]', doesn't the latter depends upon the 'C' locale and the ASCII character encoding, whereas the former is independent of locale and character set. (Note that the brackets in these class names are part of the symbolic names, and must
Be authorized ded in addition to the brackets delimiting the bracket expression .)

[$] Square brackets contain a matching character range. Adding a ^ in front of it indicates that the specified character range does not match.
$ Ereg indicates a variable, that is, $ indicates a variable. The overall meaning of this formula is:
Ereg indicates a string with a letter starting with a letter and a second character or number.

Example:
Copy codeThe Code is as follows: preg_replace ("/([[: alnum:] | [[: space:] | [[: punct:]) +/U ",'', $ string );

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.