Re: [pcre-dev] Backreference Question

トップ ページ
このメッセージを削除
著者: Philip Hazel
日付:  
To: Ralf Junker
CC: pcre-dev
題目: Re: [pcre-dev] Backreference Question
On Wed, 28 Mar 2007, Ralf Junker wrote:

> Given this pcretest syntax:
>
> /\w+(?<!\z)/g
>     abcde
>     one two three

>
> The very last character of a subject never matches. I was expecting
> that it would: The assertion at the end of the subject should find
> that the last character is not the end of the subject.


> Is the observed behaviour is correct (7.0 as well as 7.1 RC 3)?


The same behaviour is observed with Perl. (That's always the first test
I do when people ask this kind of question.)

It is also the correct behaviour. It swallows abcde, then does a
backward assertion (lookbehind). In this case, the amount to move back
is zero characters, as there are no characters to match in the
assertion. So it is still at the end of the string. The assertion is
that it should not be at the end of the string. So the assertion fails.
So it backs up one of the \w characters.

You could have used a forward assertion: in this example it has the same
effect.

What were you actually trying to match?

Philip

--
Philip Hazel, University of Cambridge Computing Service.