From: Tony Johansson on
Hi!

I understand this one.
MatchCollection matches = Regex.Matches("I'lgl some some is is a ",
@"(?<char>\s\w+)\k<char>");

I don't understand how this one works but it gives there matches. Can
somebody explain how this works.
MatchCollection matches = Regex.Matches("aababb", @"(?<l>a)(?<l>\\lb)*");

//Tony


From: Harlan Messinger on
Tony Johansson wrote:
> Hi!
>
> I understand this one.
> MatchCollection matches = Regex.Matches("I'lgl some some is is a ",
> @"(?<char>\s\w+)\k<char>");
>
> I don't understand how this one works but it gives there matches. Can
> somebody explain how this works.
> MatchCollection matches = Regex.Matches("aababb", @"(?<l>a)(?<l>\\lb)*");

The group (?<1>a) matches the first "a" and names the group "1".

In the group (?<1>\\1b) the "\\1" refers to group "1", which matches the
second "a", and the "b" matches the first "b". In other words, this
group has matched "ab", and the ?<1> redefines group "1" to reference
this match. So now we've matched the first "aab".

We reach the *, so we try to apply (?<1>\\1b) again. The \\1 now matches
ab if it finds it at the current position--and it does (the "ab" that
follow the first "aab" in the original string). The "b" in the pattern
matches the final "b" in the original string. And now we are at the end
of the string.

To summarize: the first group matched "a", the second group matched "ab"
the first time through, and then the second group matched "abb" the
second time through. The pattern also matches strings like "aababbabbb"
and "aababbabbbabbbbabbbbbabbbbbb".