php-preg-1

WBOY
Release: 2016-08-08 09:20:41
Original
939 people have browsed it

Q. Regular expression

Regular expression is composed of atoms, metacharacters and pattern modification. Atoms are just ordinary characters.

Metacharacters:

d: Match any decimal digit [0-9]

s: Match any whitespace character

w: Match any number, letter, underscore [0-9a-zA-Z_]

.: Match any character except the newline character

?: Match 0 or once

+: Match the preceding atom 1 or more times

*: Match any number of times

|: Match two Or multiple branch choices, used to separate multiple-choice patterns

b: Match word boundaries

B: Non-word boundaries

^: Match the beginning of the input string

$: Match the end of the input string Position

(): Pattern unit, multiple atoms are composed of large atoms as one unit. This will store relevant matches in a cache that can be retrieved for later use. The buffers in which submatches are stored are numbered starting from 1 and going up to 99. Each buffer can be accessed using n. Pay attention to escaping when using in regular expression patterns. For example: "/^d{4}(W)d{2}1d{2}$/". Non-storage mode can be set using ?:s in parentheses.

The inner workings of the regular expression engine

Knowing how the regular expression engine works can help you quickly understand why a certain regular expression doesn't work as you expect.

<code>  有两种类型的引擎:文本导向(text-directed)的引擎和正则导向(regex-directed)的引擎。Jeffrey Friedl把他们称作DFA和NFA引擎。本文谈到的是正则导向的引擎。这是因为一些非常有用的特性,如“惰性”量词(lazy quantifiers)和反向引用(backreferences),只能在正则导向的引擎中实现。所以毫不意外这种引擎是目前最流行的引擎。
</code>
Copy after login

You can easily tell whether the engine used is text-oriented or regular-oriented. If backreferences or "lazy" quantifiers are implemented, you can be sure that the engine you are using is regex-oriented. You can do the following test: change the regular expression <

The above has introduced php-preg-1, including various aspects. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template