Message from discussion backward reference
Received: by 10.58.255.136 with SMTP id aq8mr9426236ved.29.1351624997977;
Tue, 30 Oct 2012 12:23:17 -0700 (PDT)
Received: by 10.220.219.69 with SMTP id ht5ls255661vcb.7.gmail; Tue, 30 Oct
2012 12:23:11 -0700 (PDT)
Received: by 10.52.66.235 with SMTP id i11mr6370485vdt.7.1351624991789;
Tue, 30 Oct 2012 12:23:11 -0700 (PDT)
Date: Tue, 30 Oct 2012 12:23:11 -0700 (PDT)
From: Ben Fritz <fritzophre...@gmail.com>
Subject: Re: backward reference
Content-Type: text/plain; charset=UTF-8
On Tuesday, October 30, 2012 1:22:18 PM UTC-5, niva wrote:
> I am using this kind of code in order to modify line content :
> let patternOfxembh='^.*one="\(\d\+\)".*two="\(\d\+\)"'
> if line =~ patternOfxembh
> echo line
> The recognition is working well and then I can echo my line but is it possible to do an echo of backward reference: value of \(\d\+\).
> I would like to avoid to use substitute and using again the same pattern on the line.
You cannot use the captured groups at a later time after doing a =~ or substitute().
However, you can use the matchlist() function to give you a list of all the matches which you can use later. This function returns an empty list if there are no matches, so to avoid doing regex matching twice you could do:
let lineMatches = matchlist(...)