Thursday, February 17, 2011

Re: matchstr() question.

On 18/02/11 12:59 AM, Alessandro Antonello wrote:
> Hi, all.
>
> I'm trying to build a function that separates file names from full paths. I
> was using matchstr() function but there is a problem. It doesn't return
> anything. For example:
>
> :echo matchstr("~/.vim/atpl/class.h", "/\w\+\.h$")

Because you are writing your string in double quotes, you need to use
two backslashes each time you want one backslash to be part of your
regular expression.

Either double all your backslashes, or use a single-quoted string.

:help expr-string
:help literal-string

Ben.

> Doesn't print anything but:
>
> :echo matchstr("~/.vim/atpl/class.h", "/class\.h")
>
> Does print '/class.h' in the command line. What is wrong with that first
> regular expression? For testing it I tried the find command:
>
> /\/\w\+\.h$
>
> And it worked fine searching for a text in a buffer. But I don't understand
> why the expression doesn't work in the matchstr() function.
>
> I use MacVim 7.3.
>
> Regards,
> Alessandro Antonello
>

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