Several things:
The final capture group at the end of the pattern is:
( .*|(?!.))
which is a pretty strange thing:
capture
either:
a space followed by 0 or more
any character
or
Match if suffix (
any single character) is absent.
The whole rest of the pattern is a single capture group so whatever its parts matches is also captured as a whole in that group.
The
Match
returned by
Regex.Match()
will always report as its
Value
the entire part of the input that caused the match to succeed. This is the same as
match.Groups(0)
The other
numbered capture groups start at
.Groups(1)
.
The pattern and example string you gave returns:
match.Groups.Count = 6
match.Groups(0) = "String goaway String"
match.Groups(1) = "String goaway String"
match.Groups(2) = "String goaway "
match.Groups(3) = ""
match.Groups(4) = "String"
match.Groups(5) = ""
match.Groups("return") = "String"
match.Groups("return2") = ""
I suggest using
Expresso[
^] which is an excellent FREE tool for building and testing regular expressions.