On 9/19/06, Thomas Holder <[EMAIL PROTECTED]> wrote:
Hi,
when matching regular expressions with perl, backreferences will be
stored in $1 to $9. Does vim do anything similar? I have a script with
several lines like this
if cline =~ '^\s*[._a-z0-9]\+\s\+\([-._a-z0-9]\+\)\s\+'
...
endif
and I'd like to have the part which is in parantheses just like in perl.
I could not find anything about backreferences in the vim manual.
You can use substitute as follows:
let patt='^\s*[._a-z0-9]\+\s\+\([-._a-z0-9]\+\)\s\+'
if cline =~ patt
let _1 = substitute(cline, patt, '\1', '')
let _2 = substitute(cline, patt, '\2', '')
let _3 = substitute(cline, patt, '\2', '')
Yakov
P.S.
\1,\2,\1 are avaibale at the to-part of substitution
(:help submatch, :help sub-replace-special). But AFAIK,
these \1,\2,etc are not kept around after substitution or
after match.