Monday, September 17, 2012

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

On Saturday, September 15, 2012 3:10:49 PM UTC-5, Martin Jiricka wrote:
> Dear vim users,
>
>
>
> I do not understand why output of this command: `echo
>
> matchstr('123abc','\v(123)\@=abc')` is `123abc`. I'm using zero-width
>
> pattern, so I would like to get just `abc`. What am i doing wrong?
>
>

Since you're using "very magic", \@= isn't a zero-width match for the preceding atom. It's an optional match for a literal '@' character. :help /\=.

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 think you wanted one of these:

\v(123)@<=abc
\(123\)\@<=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: