Q. Regular Expressions
Regular expressions are made up of atoms, meta-characters, and pattern corrections in three parts. The atom is also the ordinary character.
Metacharacters
\d: Matches any decimal number [0-9]
\s: Matches any white space character
\w: Matches any number, letter, underscore [0-9a-za-z_]
.: Matches any of the characters except the newline character alien
?: Match 0 or one time
+: Match 1 or more times before the atom
*: Matches any time
|: Match two or more branch selections to separate the mode of multiple selection
\b: Match the boundaries of a word
\b: Non-word boundary
^: match the starting position of the input string
$: Match the end position of the input string
(): A mode unit that makes a large atom of multiple atoms, as a unit. This stores the relevant match in a buffer and can be retrieved for later use. The buffer number for the storage sub-match starts at 1, up to 99, and each buffer can be accessed using \ n. Be aware of escaping when used in regular expression patterns. For example: "/^\d{4} (\w) \d{2}\1\d{2}$/". Can be used in parentheses?: S to set non-storage mode.
The internal working mechanism of the regular expression engine
Knowing how the regular expression engine works helps you quickly understand why a regular expression doesn't work as you expect.
有两种类型的引擎:文本导向(text-directed)的引擎和正则导向(regex-directed)的引擎。Jeffrey Friedl把他们称作DFA和NFA引擎。本文谈到的是正则导向的引擎。这是因为一些非常有用的特性,如“惰性”量词(lazy quantifiers)和反向引用(backreferences),只能在正则导向的引擎中实现。所以毫不意外这种引擎是目前最流行的引擎。
You can easily tell if the engine you are using is text-oriented or regular-oriented. If a reverse reference or "lazy" quantifier is implemented, you can be sure that the engine you are using is regular-oriented. You can test the following: Regular Expressions <
The above describes the php-preg-1, including aspects of the content, I hope that the PHP tutorial interested in a friend helpful.