Match Class (arExpressions)

Match Class (arExpressions)

The .NET API Reference documentation has a fresh home. Visit the .NET API Browser on to see the fresh practice.

Represents the results from a single regular expression match.

Assembly: System (in System.dll)

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 RegexOptions . RightToLeft option). The collection may have zero or more items.(Inherited from Group.)

Gets the empty group. All failed matches come back this empty match.

Gets a collection of groups matched by the regular expression.

The position in the original string where the very first character of the captured substring is found.(Inherited from Capture.)

Gets the length of the captured substring.(Inherited from Capture.)

Comes back the name of the capturing group indicating by the current example.(Inherited from Group.)

Gets a value indicating whether the match is successful.(Inherited from Group.)

Gets the captured substring from the input string.(Inherited from Capture.)

Determines whether the specified object is equal to the current object.(Inherited from Object.)

Permits an object to attempt to free resources and perform other cleanup operations before it is reclaimed by garbage collection.(Inherited from Object.)

Serves as the default hash function. (Inherited from Object.)

Gets the Type of the current example.(Inherited from Object.)

Creates a shallow copy of the current Object.(Inherited from Object.)

Comebacks a fresh Match object with the results for the next match, commencing at the position at which the last match ended (at the character after the last matched character).

Comes back the expansion of the specified replacement pattern.

Comes back a Match example equivalent to the one supplied that is suitable to share inbetween numerous threads.

Retrieves the captured substring from the input string by calling the Value property. (Inherited from Capture.)

The Match object is immutable and has no public constructor. An example of the Match class is returned by the Regex . Match method and represents the very first pattern match in a string. Subsequent matches are represented by Match objects returned by the Match . NextMatch method. In addition, a MatchCollection object that consists of zero, one, or more Match objects is returned by the Regex . Matches method.

If the Regex . Matches method fails to match a regular expression pattern in an input string, it comes back an empty MatchCollection object. You can then use a foreach construct in C# or a For Each construct in Visual Basic to iterate the collection.

If the Regex . Match method fails to match the regular expression pattern, it comes back a Match object that is equal to Match.Empty . You can use the Success property to determine whether the match was successful. The following example provides an illustration.

If a pattern match is successful, the Value property contains the matched substring, the Index property indicates the zero-based kicking off position of the matched substring in the input string, and the Length property indicates the length of matched substring in the input string.

Because a single match can involve numerous capturing groups, Match has a Groups property that comebacks the GroupCollection. The Match example itself is equivalent to the very first object in the collection, at Match.Groups[0] ( Match.Groups(0) in Visual Basic), which represents the entire match. You can access the captured groups in a match in the following ways:

You can iterate the members of the GroupCollection object by using a foreach (C#) or For Each (Visual Basic) construct.

You can use the GroupCollection.Item[Int32] property to retrieve groups by the number of the capturing group. Note that you can determine which numbered groups are present in a regular expression by calling the example Regex . GetGroupNumbers method.

You can use the GroupCollection.Item[String] property to retrieve groups by the name of the capturing group. Note that you can determine which named groups are present in a regular expression by calling the example Regex . GetGroupNames () method.

The following examples use the regular expression Console\.Write(Line)?. The regular expression is interpreted as goes after:

Match the string “Console.Write”. Note that the “.” character is escaped so that it is interpreted as a literal period rather than as a wildcard that matches any character.

Match zero or one occurrence of the string “Line”.

The following example calls the Regex . Matches (String, String) method to retrieve all pattern matches in an input string. It then iterates the Match objects in the returned MatchCollection object to display information about each match.

The following example calls the Match (String, String) and NextMatch methods to retrieve one match at a time.

Available since 8

Available since 1.1

Available since Two.0

Windows Phone Silverlight

Available since 7.0

Available since 8.1

Any public static ( Collective in Visual Basic) members of this type are thread safe. Any example members are not ensured to be thread safe.

Related movie: Utter MATCH – Rusev vs. Roman Reigns – U.S. Title Match: WWE Clash of Champions 2016

Leave a Reply

Your email address will not be published. Required fields are marked *