PHP Regular Expression review (2)--Basic syntax

Source: Internet
Author: User
Tags php regular expression
1. Add "/....../" to both sides of the delimiter and use "#......#"

2. Atoms visible Atoms & smallest units of invisible atoms

Visible atoms: Characters that can be seen with the naked eye

Invisible atoms: atoms that are invisible to the naked eye, such as: \ n line break \ t tab

Suggestion: In about Chinese characters to match, first go to Webmaster tools, the Chinese characters into Unicode encoding, in the match, you can avoid coding different errors produced.

3. Meta-Characters

How to filter atoms

| Match two or more branch selections.

[.......] Matches any one of the atoms in the square brackets

[^.......] Match any character except the atoms in square brackets, note: [^ These two symbols must be joined together.

The collection of atoms

. Matches any character except the line break. equivalent to [^\n]

\d matches a decimal number [0-9]

\d matches a non-decimal number [^0-9]

\s matches an invisible atom [\t\n\r\f\v]

\s matches any one visible atom [^\t\n\r\f\v]

\w matches any number, letter, underscore [0-9a-za-z_]

\w matches any one non-digit, letter, underscore [^0-9a-za-z_]

4. quantifiers not only support atoms, they also support the collection of atoms.

{n} The atom in front of it just appears n times

{n,} The atoms in front of it appear at least n times

{n,m} The atom in front of it appears at least n times, with a maximum of M times

* Match 0 times, 1 times, multiple {0,}

+ match 1 times, multiple {1,}

? Match 0 times, 1 times {0,1}

5. Border control

^ Must start with the next atom.

$ must end with the one atom before

() match the whole of which is an atom

  • Related Article

    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.