

Gets a value indicating whether the match is successful. Returns the name of the capturing group represented by the current instance. Gets the length of the captured substring.

The position in the original string where the first character of the captured substring is found. Gets a collection of groups matched by the regular expression. All failed matches return this empty match.

The collection may have zero or more items. Gets a collection of all the captures matched by the capturing group, in innermost-leftmost-first order (or innermost-rightmost-first order if the regular expression is modified with the RightToLeft option). Note that you can determine which named groups are present in a regular expression by calling the instance Regex.GetGroupNames() method. You can use the GroupCollection.Item property to retrieve groups by the name of the capturing group. Note that you can determine which numbered groups are present in a regular expression by calling the instance Regex.GetGroupNumbers method. You can use the GroupCollection.Item property to retrieve groups by the number of the capturing group. You can iterate the members of the GroupCollection object by using a foreach (C#) or For Each (Visual Basic) construct. You can access the captured groups in a match in the following ways: The Match instance itself is equivalent to the first object in the collection, at Match.Groups ( Match.Groups(0) in Visual Basic), which represents the entire match. If a pattern match is successful, the Value property contains the matched substring, the Index property indicates the zero-based starting position of the matched substring in the input string, and the Length property indicates the length of matched substring in the input string.īecause a single match can involve multiple capturing groups, Match has a Groups property that returns the GroupCollection. It then iterates the Match objects in the returned MatchCollection object to display information about each match. The following example calls the Regex.Matches(String, String) method to retrieve all pattern matches in an input string. Match zero or one occurrence of the string "Line". Note that the "." character is escaped so that it is interpreted as a literal period rather than as a wildcard that matches any character. The regular expression is interpreted as follows: The following examples use the regular expression Console\.Write(Line)?.
