On Fri, Nov 24, 2017 at 11:30:03AM +0100, Christian Brabandt wrote:
> Hi,
> while writing the test for checking the URLs I stumbled on this 
> difference between submatch(1) and \1:
> #v+
> let a = '    https://www.vim.org   '
> let g:pat = '.\{-}\(http[^ ]*\).\{-}$'
> echo substitute(a, g:pat, submatch(1), '')
> echo substitute(a, g:pat, '\1', '')
> #v-
> 
> If you execute this piece of script, the first map() returns an empty 
> list, while the second map() returns the URL stripped by whitespace 
> (which would be my expected behaviour for both map() calls).
> 
> Is this expected?

You're calling submatch(1) and then passing the returned value to substitute().
Try

    echo substitute(a, g:pat, '\=submatch(1)', '')

or

    echo substitute(a, g:pat, {m->submatch(1)}, '')

or

    echo substitute(a, g:pat, {m->m[1]}, '')

Marius Gedminas
-- 
Initially, there were few or no postal regulations governing packages mailed
parcel post. To construct a bank in Vernal, Utah in 1916, a Salt Lake City
Company figured out that the cheapest way to send 40 tons of bricks to the
building was by Parcel Post. Each brick was individually wrapped & mailed.
Postal rules were promptly rewritten.
        -- http://en.wikipedia.org/wiki/United_States_Postal_Service

-- 
-- 
You received this message from the "vim_dev" 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_dev" 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/d/optout.

Attachment: signature.asc
Description: PGP signature

Raspunde prin e-mail lui