Tuesday, September 18, 2012

Re: Why matchstr returns also text matched by zero-width pattern?

On Monday, September 17, 2012 12:07:58 PM UTC-5, Martin Jiricka wrote:
> Hello!
>
>
>
> First of all, thank you for your reply!
>
>
>
> > I think you wanted one of these:
>
> > \v(123)@<=abc
>
>
>
> Yes, this is what I wanted.
>
>
>
> > Additionally, if this WERE working as you expect, your pattern would NEVER
>
> > match. You are saying,
>
> > "match abc where 123 also matches in the same position"
>
> > which cannot possibly succeed, because 123 does not match where abc matches.
>
>
>
> I don't get this. Of course I didn't want to match 'abc' on '123'. (That's the purpose of regexes, match pattern where the pattern match, I would say...?) I posted simplified example, originally I wanted to match last word before the parenthesis, which is a function name. The '@<=' works fine for this.
>
>

Yes, and @<= is what you wanted. You used @=, which is a zero-width look-ahead, not a look-behind.

E.g. /\(abc\)\@=\a\+ will match the whole string "abcdefghij"; it says "find a string of alphabetic characters starting with 'abc'". /\(abc\)\@<=\a\+ will match the "defghij" in "abcdefghij" only; it says, "find a string of alphabetic characters preceded by 'abc'".

--
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: