Parse PHP Regular Expression metacharacters

Source: Internet
Author: User

What are metacharacters in PHP regular expressions? What should we pay attention to when using PHP Regular Expression metacharacters? Here we will introduce you in detail the types of PHP Regular Expression metacharacters and the methods used.

PHP Regular Expression metacharacters:

◆ Braces

◆ Plus sign

◆ Asterisk

◆ Question mark

Use of PHP Regular Expression metacharacters:

PHP Regular Expression metacharacters are special characters in PHP regular expressions. They are used to describe the appearance of their leading characters (that is, the characters before the metacharacters) in matched objects. Metacharacters are single characters, but different or identical metacharacters can be combined to form large metacharacters.

◆ Braces: braces are used to precisely specify the number of occurrences of matching metacharacters.

For example, "/pre {}/" indicates that the matched objects can be "pre", "pree", and "preeeee". In this way, one to five "e" appear after "pr ".. Or "/pre {, 5}/" indicates that pre appears between 0 and 5 times.

◆ Plus sign: the "+" character is used to match the character before the metacharacters once or multiple times

For example, "/ac +/" indicates that the matched object can be "act", "account", and "acccc". One or more "c" objects appear after "". string. "+" Is equivalent to "{1 ,}".

◆ Asterisk: "*" is used to match zero or multiple times before the metacharacters

For example, "/ac */" indicates that the matched object may be "app", "acp", and "accp". There may be zero or multiple "c" after "". "*" Is equivalent to "{0 ,}".

◆ Question mark :"? "Character is used to match the character before the metacharacters zero or one time

For example, "/ac? /"Indicates that the matched object can be" a "," acp ", and" acwp ". In this way, zero or one" c "string appears after". "? "There is also a very important role in regular expressions, that is," greedy mode ".

A Brief Introduction to PHP Regular Expression metacharacters will help you understand and master PHP Regular Expression metacharacters.


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.