[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: [TSVN] regex help

From: Douglas Stonham <dstonham_at_pennysaverusa.net>
Date: 2005-02-18 00:03:16 CET

On Thu, February 17, 2005 1:29 pm, SteveKing said:
> Eric J. Smith wrote:
>> [Ii]ssue:?(?:(?:,\s*|\s*,?\s+[Aa]nd\s+|\s+)\#?(\d+))+
>> Issue #8,9, #10, #11 , and #12
>
> Capturing is not the problem here! It's the returned groups! Since
> groups are numbered from 0 to X with 0 being the whole match and the 1
> being the first group, 2 being the second this will only return the
> first bug ID in group 1.

Interestingly, it seems that the .net regex has indeed been extended to
allow for this. I didn't believe it at first but having looked at the
code for the Regular Expression Workbench I found that .net has matches
(the whole match string), containing groups (the named/numbered groups in
the regex), containing 'captures' (things that the groups matched 'on the
way').

----
Dim r As New Regex(txtPattern.Text)
Dim mc As MatchCollection
Dim gc As GroupCollection
Dim cc As CaptureCollection
Dim i, j, k As Integer
mc = r.Matches(txtInput.Text)
For i = 0 To mc.Count - 1
    gc = mc(i).Groups
    For j = 0 To gc.Count - 1
        cc = gc(j).Captures
        For k = 0 To cc.Count - 1
            litMatches.Text += "<br>" + i.ToString + ":" + j.ToString +
":" + k.ToString + ":" + cc(k).Value()
        Next
    Next
Next
----
Produces:
0:0:0:Issue #8,9, #10, #11 , and #12
0:1:0:8
0:1:1:9
0:1:2:10
0:1:3:11
0:1:4:12
Unfortunately, I have never heard of a regex engine doing this before so
it is unlikely that GRETA supports it, but still interesting.
Douglas
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tortoisesvn.tigris.org
For additional commands, e-mail: dev-help@tortoisesvn.tigris.org
Received on Fri Feb 18 00:04:27 2005

This is an archived mail posted to the TortoiseSVN Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.