Two points about PHP regular expressions

zhaozj2021-02-16  63

several tips about Regular Expressions1. process for "greedy" By default, the quantifiers are "greedy", that is, they match as much as possible (up to the maximum number of per- mitted times), without causing the rest of the pattern to fail. The classic example of where this gives problems is in trying to match comments in C programs. These appear between the sequences / * and * / and within the sequence, individual * and / characters may appear. An attempt to match C com - Ments by Applying The Pattern

//*.*/*/

To the string

/ * first command * / not comment / * second comment * /

Fails, Because It matches the entire string due to the greediness of the. * iTem.

However, if a quantifier is stocked by a quantifier is flollowed by a quantifier, then it ceases to be bigy, and instead matches the minimum number of times Possible, so the pattern

//*.**/////

Summary:? There are similar functions with / u, but at the same time

As follows:

2.assertions / w (? =;)

Matches a Word Followed by A SEMICOLON, But Does Not Include The Semicolon in The match, and

Foo (?! bar)

Matches Any Occurrence of "foo" That Is Not Followed by "bar". Note That the apparently Similar Pattern

Small knot: (?!) Only forward judgment, such as bar (?! Foo), (?! Foo) Bar does not make sense (?

转载请注明原文地址:https://www.9cbs.com/read-23809.html

New Post(0)