[prev in list] [next in list] [prev in thread] [next in thread]
List: vim
Subject: Re: Help on the usage of \_s atom
From: Bram Moolenaar <Bram () moolenaar ! net>
Date: 2004-03-26 11:22:08
Message-ID: 200403261122.i2QBM8vs005344 () moolenaar ! net
[Download RAW message or body]
Hari Krishna Dara wrote:
Note in advance: This is about matching with strings, not about matching
in buffer text.
> I am confused on how this atom is supposed to work (see |\_|). The doc
> says that it should match newline in addition to the whitespace (because
> of the "_"), but I am not getting good results with it. Here are some
> examples that I though should work, but they don't:
>
> While searching for '\_s\+' I see that it is not matching spaces across
> newlines.
> asdf
>
> ab<space><space>
> cd
>
> I expected it to match everthing between b and c. I am actually
> surprised that even searching for '\(\_s\|\n\)\+' or '\(\s\|\n\)\+' is
> not working in this case, however I think that is just how the search
> works, as the following works as expected.
>
> :echo strlen(matchstr("ab \n cd", '\(\s\|\n\)\+'))
> 5
>
> but not the following:
>
> :echo strlen(matchstr("ab \n cd", '\_s\+'))
> 2
>
> Even the following doesn't work:
>
> :echo " \n " =~ '^\_s*$'
> 0
>
>
> It is possible that I am missing something here. I appreciate any help
> in understanding this.
In strings the "\n" character is handled as a character, not as a real
line break. This can indeed be annoying, since all the extra items in
regexp patterns for working with line breaks won't work.
I'll look into handling "\n" in a string like a line break in a line for
patterns. The example above works now, but I have to check for
undesired side effects and whether there are more places where a "\n" in
text is to be handled like a line break.
--
hundred-and-one symptoms of being an internet addict:
146. You experience ACTUAL physical withdrawal symptoms when away
from your 'puter and the net.
/// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
/// Sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ Project leader for A-A-P -- http://www.A-A-P.org ///
\\\ Buy at Amazon and help AIDS victims -- http://ICCF.nl/click1.html ///
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic