Two PHP regular expressions special character _ PHP Tutorial

Source: Internet
Author: User
Tags php regular expression
Describes two special characters in the PHP regular expression. What are the special characters [] and in PHP regular expressions? What are the specific operations? Why are they Special characters? what are the special characters "[]" and "" in PHP Regular Expressions? what are they? What are the specific operations? Why are they Special characters? Let's take a look at the specific introduction.

There are two important special characters: "[]". They can match any character in "[]", for example, "/[az]/" can match a single character "a" or "z "; if you change the expression above to "/[a-z]/", you can match any single lowercase letter, such as "a" and "B.

For PHP regular expression special characters "[]":

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

◆ [: Alpha:]: match any letter

◆ [: Alnum:]: match any letter or number

◆ [: Digit:]: match any number

◆ [: Space:]: matches space characters

◆ [: Upper:]: match any uppercase letter

◆ [: Lower:]: match any lowercase letter

◆ [: Punct:]: match any punctuation marks

◆ [: Xdigit:]: match any hexadecimal number

PHP regular expression special character "":

The following special characters indicate the following meanings after the escape symbol "" Is escaped:

◆ S: match a single space character

◆ S: used to match all characters except a single space character.

◆ D: used to match numbers from 0 to 9, which is equivalent to "/[0-9]/".

◆ W: used to match letters, numbers or underscores, equivalent to "/[a-zA-Z0-9 _]/".

◆ W: used to match all the characters that do not match w, equivalent to "/[^ a-zA-Z0-9 _]/".

◆ D: used to match any non-decimal numeric characters.

. ◆: Used to match all characters except line breaks. if the modifier "s" is used, "." can represent any character.

We will introduce you to the introduction of special characters in PHP regular expressions. I hope that will help you understand and master the use of special characters in PHP regular expressions.


"[]" And "", so what are they? What are the specific operations? Why are they Special characters? is there anything special during use...

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.