Thursday, August 18, 2011

Re: Matches with zero width if the preceding atom does NOT match at the current position.

Hi,

One mailing list is probably enough to post your questions to! :-) I'm
only replying on vim_use.

On 19/08/11 2:02 AM, baumann Pan wrote:
> Hi Gurus,
>
> I could not understand the descriptions below about the usage of \@!.
> "a.\{-}p\@!" will match any
> "a", "ap", "aap", etc. that isn't followed by a "p", because the "."
> can match a "p" and "p\@!" doesn't match after that.
>
> I know why "a" matches the pattern. but I don't understand why "ap"
> could match the pattern "a.\{-}p\@!", so does "aap".
> why "appppp" also matches the pattern?

It only matches if it has something after it that is not a "p".

The expanded pattern is

a.....p\@!

The "a....." matches "appppp" and the "p\@!" ensures there is no "p"
coming next, though without including that character in the match.

> from the pattern "a.\{-}p\@!", I can tell:
> if the pattern is a.\{-}p, it will match ap, aaaap and
> absdfasdfasdasdfasdp since .\{-} could be 0 to more chars as few as
> possible, but followed with a p.

That's true. However "a.\{-}p" is not part of the pattern. The final "p"
has a different meaning because of the "\@!" following it.

"p\@!" is not the same as "[^p]". It does not match something that is
not a "p", it just checks that something that there isn't a "p" 'ready'
to be matched. Whatever is there (if anything) isn't actually matched.

> if \@! is after p, does it mean p should not appear at the end?

It means "p" should not appear *after* the end.

> why ap is ok?

It is only OK if it is in the context of something not followed by a
"p". So if you had the word "apt", the "ap" would match, because
"a.\{-}" matches "ap" and "p\@!" succeeds because "t" is not "p".

Does that help?

Smiles,

Ben.

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments: