Hi Marc!

On So, 17 Feb 2013, Marc Weber wrote:

> I expect the following to output 1 (be equal), but its not. I don't 
> understand why
> 
> echo  substitute("-D abc\nfoo/bar\n-L x", "-[DL][ ]*[^\n]*",'','g') 
>  \ == substitute("-D abc\nfoo/bar\n-L x", '-[DL][ ]*[^\n]*','','g')
> 
> Why do I expect so ? because "[\n]" should be the same as '[\n]' - however
> '[\n]' should be replaced by chr(10) by the pattern interpreter according to 
> help:
> 
> according to :h pattern.txt /A collection.  This is a sequence of characters 
> enclosed in brackets
>       - The following translations are accepted when the 'l' flag is not
>         included in 'cpoptions' {not in Vi}:
>           [..]
>               \n      line break, see above |/[\n]|
> 
> Which piece am I missunderstanding?

I think, you are seeing some kind of inconsistency here. The problem is, 
that '[^\n]' does match newlines. This is allowed so that in a text 
which is shown by vim as "A^@A" or "A^MA" the '.' also matches those 
control chars carrige return / line feed.

Thus the '[^\n]*' matches everything and so everything is replaced.

I thought about changing it, but that would be an incompatible change 
(and in fact already fails some tests). I have briefly mentioned this 
here:
     https://groups.google.com/d/topic/vim_dev/DzJ7ZzYlzQI/discussion

regards,
Christian

-- 
-- 
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 [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to