On 2019-06-22 08:56, ph10 wrote:
On Fri, 21 Jun 2019, ND via Pcre-dev wrote:
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?
/\A.*\b(\w++)(?>.*?\b\1\b){9}/
You do not need a lookahead to do this.
Your example is not working right (let's change 10 to 3 for simplicity):
/\A.*\b(\w++)(?>.*?\b\1\b){2}/
word1 word1 word2 word2 word2 word1
0: word1 word1 word2 word2 word2
1: word2
We want to capture "word1" as most closer to the end of text. But "word2"
captures.
--
## List details at https://lists.exim.org/mailman/listinfo/pcre-dev