PHP regular Expression Special characters [: Alnum:] [: Alpha:]--Regular expressions

Source: Internet
Author: User
Tags control characters ereg locale lowercase php regular expression printable characters uppercase letter alphanumeric characters
If "^" appears in "[]", this expression does not match the characters appearing in "[]", such as "/[^a-z]/" does not match any lowercase letters! And the regular expression gives several default values for "[]", as follows:

' [: alnum:] ' matches any letter
Alphanumeric characters: ' [: Alpha:] ' and ' [:d igit:] '.

' [: 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 through 037, and 177 (' DEL '). In other character sets, this are the equivalent characters, if any.

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

' [: Graph:] '
Graphical characters: ' [: alnum:] ' and ' [:p UNCT:] '.

' [: 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 '.
' [:p rint:] '
printable characters: ' [: alnum:] ', ' [:p unct:] ', and space.

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

' [: Space:] ' match spaces
Space Characters:tab, newline, vertical tab, form feed, carriage
return, and spaces.

' [: 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 16 binary digits
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] ', except the latter depends upon the ' C ' locale and the ASCII character Enco Ding, whereas the former is independent of locale and character set. (Note this brackets in this class names are part of the symbolic names, and must
be included into addition to the brackets delimiting the bracket expression.)

[$] The square brackets contain a range of matching characters, preceded by ^, that is, the specified character range is not matched.
$ereg represents a variable, which is the symbol of a variable, and the whole meaning of the formula is:
Ereg represents a string with all strings beginning with a letter and the second is a letter or a number.

Example:
Copy Code code as follows:
Preg_replace ("/" [[: alnum:]]|[ [: space:]]| [[:p UNCT:]]) +/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.