perhaps help further.
On 19/08/11 2:24 PM, baumann Pan wrote:
> HI Ben,
> Thanks in advance.
> Still have question.
>
>>> 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.
> An example to explain the above? Thanks.
Well, consider the text "app". Since there is \{-} involved, we start
with the shortest potential match and lengthen it character by
character.
- "a" can be matched by "a.\{-}" (0 repeats of "."), but after the end
of the match is "pp", so since "p" matches (the beginning of) that,
"p\@!" causes the match to fail. So "a" does not match.
- "ap" can be matched by "a.\{-}" (1 repeat of "."), but after the end
of the match is "p", so since "p" matches that, "p\@!" causes the
match to fail. So "ap" does not match.
- "app" can be matched by "a.\{-}" (2 repeats of "."), and after the end
of the match is nothing. "p" does not match nothing, so "p\@!" causes
the match to succeed. So "app" matches.
Notice how the final decision about whether the text matches or not is
made by looking at what is after the actual match.
Also notice how the \{-} interacts with the \@! also. They don't act
independently. If the \@! causes the match to fail, the \{-} will still
keep trying longer matches until one succeeds.
>>> 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".
>>
> if the pattern is a.\{-}, the ap will not matched with the pattern,
> why ap could match the a.\{-}p\@!? what's the difference? Thanks!
Well, "a.\{-}" on its own won't match anything except "a" because the
smallest number of repeats of "." is always going to be zero. It is what
comes after that part of the pattern that restricts it. Because there is
"p\@!" after the ".\{-}", zero repeats will not work, because if you
used zero repeats, the thing after the end of the match would be "pt",
and that would match "p". So instead, we must use one repeat of ".",
match "ap" and have "t" after the end of the match, which doesn't match
"p" (so "\@!" succeeds).
> Could you give examples when p is amony a word, /a.\{-}\@! will not match.
I think you left out a "p" there in the pattern.
It is not really possible to find examples where "a.\{-}p\@!" does not
match. You can only find examples where it might not match what you
expect. Because, like the example above, you always get to the point
where "a.\{-}" matches everything, and "p\@!" succeeds because "p"
doesn't match nothing.
So, it matches
"ap" in "apt"
"app" in "apple"
"app" in "app"
"ap" in "ap"
"a" in "a"
"ap" in "apipe"
"a" in "airpipe"
If you remove the matching text from each of them, you will notice that
the bit that is left (the bit after the match) is always the first
position (after the first "a") that "p" does not match, so the smallest
number of repeats of "." that makes a success.
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:
Post a Comment