get matched sting after search()

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

get matched sting after search()

iler.ml
How do I get the matching string search()
(what is $& in perl), or submatches (what is $1,$2 in perl) ?

Thanks
Yakov

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

To unsubscribe from this group, send email to vim_use+unsubscribegooglegroups.com or reply to this email with the words "REMOVE ME" as the subject.
Reply | Threaded
Open this post in threaded view
|

Re: get matched sting after search()

Gary Johnson-4
On 2010-03-26, Yakov wrote:
> How do I get the matching string search()
> (what is $& in perl), or submatches (what is $1,$2 in perl) ?

My first thought was to reply with

    :help sub-replace-special
    :help submatch()

but that won't help you if you are searching with search().  In that
case, Vim appears to offer only a two-step solution:

    1.  use search() to find the line matching the pattern; then
    2.  use matchlist() to find the submatches within that line,
        using the same pattern.

See

    :help matchlist()

Regards,
Gary


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

To unsubscribe from this group, send email to vim_use+unsubscribegooglegroups.com or reply to this email with the words "REMOVE ME" as the subject.
Reply | Threaded
Open this post in threaded view
|

Re: get matched sting after search()

Tony Mechelynck
In reply to this post by iler.ml
On 26/03/10 22:09, Yakov wrote:
> How do I get the matching string search()
> (what is $&  in perl), or submatches (what is $1,$2 in perl) ?
>
> Thanks
> Yakov
>

search() doesn't give that to you. You will either (without the n flag)
have to examine the line the cursor lands on, or use the p flag to see
whether a sub-pattern was matched.

See :help search()


If you can't do without perl regexp results, well,

        if has('perl')
                function s:WhateverTheName()
                        perl << EOF
                                ...perl script here...
EOF
                        " EOF (above) MUST be in column 1 !!!
                endfunction
                call s:WhateverTheName()
        else
                echoerr 'Not compiled with +perl'
        endif

see :help script-here

but then, of course, you'll be limited to Vim executables with perl
support compiled-in (and, if dynamic, a perl library that can be found
at runtime).


Best regards,
Tony.
--
A.I. hackers do it with robots.

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

To unsubscribe from this group, send email to vim_use+unsubscribegooglegroups.com or reply to this email with the words "REMOVE ME" as the subject.