: 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.