Expand the loop when to use

I am trying to understand a regex cycle in a regex. What is the big difference between:

MINISTÉRIO[\s\S]*?PÁG

and

MINISTÉRIO(?:[^P]*(?:P(?!ÁG\s:\s\d+\/\d+)[^P]*)(?:[\s\S]*?))PÁG

In this context:

http://regexr.com/3dmlr

Why should I use the second if the first does the SAME?

Thank.

+1
source share
1 answer

What is Unroll-the-loop?

See Expand the loop method :

This optimization technique is used to optimize re-rotation of a form (expr1|expr2|...)*. This expression is not uncommon, and the use of another repetition within the alternation can also lead to superlinear matching. Superlinear match occurs due to an unreachable expression (a*)*.

, , . , , . :

normal * ( *) *

, , .

, .

MINISTÉRIO[\s\S]*?PÁG - , MINISTÉRIO[^P]*(?:P(?!ÁG)[^P]*)*PÁG. . ( PCRE, ). Regex , ). text: , P. , , , , , .

. .*?, .* [^"]*+ quantifiers , , ( [\s\S]*? .*? DOTALL , . ).

? . (1-10 ). , , , .

, .

, , , , ..

:

+3

Source: https://habr.com/ru/post/1652410/


All Articles