Parsing PHP Regular expression meta-character _php tutorial

Source: Internet
Author: User
Tags php regular expression
What are the PHP regular expression meta-characters? What do we need to be aware of when we use the PHP regular expression meta-characters? So here is a detailed description of the PHP regular expression meta-character types and the method used, and so on.

PHP Regular Expression meta-character types :

Curly Braces

PLUS sign

Asterisk

Question mark

PHP Regular expression meta-characters are used specifically:

PHP Regular Expression metacharacters a class of characters in a PHP regular expression that describe the way in which the leading character (the character preceding the meta character) appears in the matched object. The meta-character itself is a single character, but different or identical meta-characters can be combined to form large meta-characters.

Curly braces: Curly braces are used to precisely specify the number of occurrences of a matching meta-character

For example, "/pre{1,5}/" means that the matching object can be "pre", "Pree", "preeeee" so that a string of 1 to 5 "E" appears after "PR". or "/pre{,5}/" on behalf of the pre appears 0 this to 5 times between.

Plus: the "+" character appears one or more times before a character is used to match a meta character

For example, "/ac+/" means that the matched object can be "act", "account", "ACCCC", and so on, after "a", one or more "C" strings. "+" equals "{1,}".

Asterisk: "*" character used to match metacharacters before characters appear 0 or more times

For example, "/ac*/" means that the matched object can be "app", "ACP", "ACCP" and so on "a" after "a" appears 0 or more "C" string. "*" corresponds to "{0,}".

Question mark: "?" Characters used to match metacharacters before characters appear 0 or 1 times

For example, "/ac?/" means that the matching object can be a "a", "ACP", "ACWP" so that a 0 or 1 "C" string appears after "a". "?" There is also a very important role in regular expressions, namely "greedy mode".

A brief introduction to the PHP regular expression metacharacters is explained here, and hopefully it will help you understand and master the PHP regular expression metacharacters.


http://www.bkjia.com/PHPjc/446587.html www.bkjia.com true http://www.bkjia.com/PHPjc/446587.html techarticle what are the PHP regular expression meta-characters? What do we need to be aware of when we use the PHP regular expression meta-characters? So here's a detailed introduction to the 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.