Php-preg-1

Source: Internet
Author: User
Tags preg expression engine
: This article mainly introduces the php-preg-1, for PHP tutorials interested in students can refer. Q. Regular expression

Regular expressions are composed of three parts: atoms, metacharacters, and pattern correction. Atoms are common characters.

Metacharacters:

\ D: match any decimal number [0-9]

\ S: matches any blank character

\ W: match any number, letter, or underline [0-9a-zA-Z _]

.: Match any character except the line break

? : Match 0 times or once

+: Match the previous atom once or multiple times

*: Match any time

|: Match two or more branch selections to separate multiple select modes

\ B: match the word boundary

\ B: non-word boundary

^: Match the start position of the input string

$: End position of matching input string

(): A Pattern unit. multiple atoms form a large atom as a unit. In this way, the matching information is stored in a cache and can be obtained for future use. The buffer number for storing sub-matches starts from 1 and ranges from 99 to 99. Each buffer can be accessed using \ n. Note the escape when using the regular expression mode. For example, "/^ \ d {4} (\ W) \ d {2} \ 1 \ d {2} $ /". Can be used in brackets? : S: Set the non-storage mode.

Internal working mechanism of the regular expression engine

Knowing how the regular expression engine works helps you quickly understand why a regular expression does not work as expected.

There are two types of engines: the text-directed engine and the regex-directed engine. Jeffrey Friedl calls them the DFA and NFA engines. This article talks about the regular expression-oriented engine. This is because some very useful features, such as lazy quantifiers and backreferences, can only be implemented in the regular expression-oriented engine. So it is not surprising that this engine is currently the most popular.

You can easily tell whether the engine is text-oriented or regular-expression-oriented. If reverse references or "inert" quantifiers are implemented, you are sure that the engine you are using is regular-oriented. You can test the regular expression as follows: <

The above introduces the php-preg-1, including the content of the aspect, hope to be interested in PHP Tutorial friends help.

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.