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)
X-BeenThere: vim_use@googlegroups.com
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>
To: vim_use@googlegroups.com
Message-Id: <d3dcc95e-c8b3-44a5-8dcd-13826c5ab66e@googlegroups.com>
In-Reply-To: <aa38392b-be19-42d7-ad7d-a203e5a6d84f@googlegroups.com>
References: <aa38392b-be19-42d7-ad7d-a203e5a6d84f@googlegroups.com>
Subject: Re: backward reference
MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary="----=_Part_593_9252350.1351624991392"
------=_Part_593_9252350.1351624991392
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
On Tuesday, October 30, 2012 1:22:18 PM UTC-5, niva wrote:
> Hi,
>
> I am using this kind of code in order to modify line content :
>
> let patternOfxembh='^.*one="\(\d\+\)".*two="\(\d\+\)"'
> if line =~ patternOfxembh
> echo line
> endif
>
> 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(...)
if !empty(lineMatches)
echo line
...
endif
------=_Part_593_9252350.1351624991392--