Sunday, February 9, 2014

Re: matchstr() ^ and $ wrong for multi-line text?

On Sunday, February 9, 2014 10:15:53 AM UTC+4, David Barnett wrote:
> I noticed that matchstr() seems to always interpret ^ as start-of-string and $ as end-of-string, even when the string is multiple lines. ":help pattern" says they should be start-of-line and end-of-line, respectively.
>
> For example
> :echo matchstr("foo\nbar", '^foo$')
> matches nothing.
>
> I don't see anything in the matchstr() help indicating that it treats start-of-line and end-of-line any differently. I tried \_^ and \_$ as well. Is this a bug?

You do not have multiline string here. See :h NL-used-for-Nul: regex engine always assumes that newline character is a mere replacement for zero byte and newline is always represented by a string end. Which is true for buffers. Not for buffers there is only `readfile()`/`getline(start, end)` format (which is a list of lines where newlines are used for nuls) which match* functions, substitute(), =~# and so on do not understand.

>
> David

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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments: