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

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

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

David Barnett
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?

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 [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.
Reply | Threaded
Open this post in threaded view
|

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

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

:help matchstr() says it's the same as match(), and the help for
that says to see ':help string-match', and that says that "\n"
can be matched with "\n", but (by implication) not by $.

John


--
--
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 [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.
Reply | Threaded
Open this post in threaded view
|

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

David Barnett
Oh yeah, huh:
  Don't forget that "^" will only match at the first character of the String and 
  "$" at the last character of the string.  They don't match after or before a   
  "\n".

Guess I just lost the scavenger hunt…

David


On Sun, Feb 9, 2014 at 2:15 AM, John Beckett <[hidden email]> wrote:
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.

:help matchstr() says it's the same as match(), and the help for
that says to see ':help string-match', and that says that "\n"
can be matched with "\n", but (by implication) not by $.

John


--
--
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 a topic in the Google Groups "vim_use" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/vim_use/eX0WwxcMj8o/unsubscribe.
To unsubscribe from this group and all its topics, send an email to [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.

--
--
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 [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.
Reply | Threaded
Open this post in threaded view
|

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

Nikolay Aleksandrovich Pavlov
In reply to this post by David Barnett
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 [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.