Autor: ND Fecha: A: Pcre-dev Asunto: Re: [pcre-dev] Some words about assertion docs
On 2019-06-20 15:40, ph10 wrote: >(?:(?=X)|(?=Y))Z means "if X matches, try to match Z; if that fails, if
> Y matches try to match Z". In the simple case the second match of Z will
> be the same as the first, so will always fail. However, if X and Y are
> complex and contain capturing parentheses, I suppose it is possible to
> construct Z using back references in such a way that it fails after X
> matches but succeeds after Y matches.
>But who would want to constuct such a complicated thing?
>
It's not complicated. It can brings more power to regexes and give
possibility to solve tasks that now are too complicated or impossible for
PCRE2.
Imagine that we have a text. There are some words in this text that occurs
at least 10 times. We want to find from they a word that is most closer to
the end of text.
If lookahead assertion is non-possessive then we can use this pattern:
\A(?=.*\b(\w++))(?>.*?\b\1\b){10}
What pattern can solve this task with current PCRE2?