System.Text.RegularExpressions.Match Class

Assembly: System.dll
Namespace: System.Text.RegularExpressions
Summary
Represents the results from a single regular expression match.
C# Syntax:
[Serializable]
public class Match : Group
Remarks
Because a single match can involve multiple capturing groups, Match has a Groups property that returns the GroupCollection. The GroupCollection has accessors that return each group.Match inherits from Group so the entire substring matched can be accessed directly. That is, the Match instance itself is equivalent to Match.Groups[0] (Match.Groups(0)) . The Match object is immutable and has no public constructor.
See also:
System.Text.RegularExpressions Namespace

System.Text.RegularExpressions.Match Member List:

Public Properties
Captures
(inherited from System.Text.RegularExpressions.Group)
Read-only

See base class member description: System.Text.RegularExpressions.Group.Captures


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.
Empty Read-only

Gets the empty group. All failed matches return this empty match.
Groups Read-only

Gets a collection of groups matched by the regular expression.
Index
(inherited from System.Text.RegularExpressions.Capture)
Read-only

See base class member description: System.Text.RegularExpressions.Capture.Index


The position in the original string where the first character of the captured substring was found.
Length
(inherited from System.Text.RegularExpressions.Capture)
Read-only

See base class member description: System.Text.RegularExpressions.Capture.Length


The length of the captured substring.
Success
(inherited from System.Text.RegularExpressions.Group)
Read-only

See base class member description: System.Text.RegularExpressions.Group.Success


Gets a value indicating whether the match is successful.
Value
(inherited from System.Text.RegularExpressions.Capture)
Read-only

See base class member description: System.Text.RegularExpressions.Capture.Value


Gets the captured substring from the input string.
Public Methods
Equals
(inherited from System.Object)
See base class member description: System.Object.Equals

Derived from System.Object, the primary base class for all objects.
GetHashCode
(inherited from System.Object)
See base class member description: System.Object.GetHashCode

Derived from System.Object, the primary base class for all objects.
GetType
(inherited from System.Object)
See base class member description: System.Object.GetType

Derived from System.Object, the primary base class for all objects.
NextMatch Returns a new Match with the results for the next match, starting at the position at which the last match ended (at the character beyond the last matched character).
Result Returns the expansion of the passed replacement pattern. For example, if the replacement pattern is $1$2, Result returns the concatenation of Groups[1].Value and Groups[2].Value (Groups(1).Value and Groups(2).Value).
Synchronized Returns a Match instance equivalent to the one supplied that is safe to share between multiple threads.
ToString
(inherited from System.Text.RegularExpressions.Capture)
See base class member description: System.Text.RegularExpressions.Capture.ToString


Gets the captured substring from the input string.
Protected Methods
Finalize
(inherited from System.Object)
See base class member description: System.Object.Finalize

Derived from System.Object, the primary base class for all objects.
MemberwiseClone
(inherited from System.Object)
See base class member description: System.Object.MemberwiseClone

Derived from System.Object, the primary base class for all objects.

Hierarchy:


System.Text.RegularExpressions.Match Member Details

Property: Captures (read-only)
Inherited
See base class member description: System.Text.RegularExpressions.Group.Captures

Summary
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.
C# Syntax:
public CaptureCollection Captures {get;}

Return to top


Property: Empty (read-only)
Summary
Gets the empty group. All failed matches return this empty match.
C# Syntax:
public static Match Empty {get;}
Remarks
This property should not be used to determine if a match is successful. Use Group.Success instead.

Return to top


Property: Groups (read-only)
Summary
Gets a collection of groups matched by the regular expression.
C# Syntax:
public virtual GroupCollection Groups {get;}

Return to top


Property: Index (read-only)
Inherited
See base class member description: System.Text.RegularExpressions.Capture.Index

Summary
The position in the original string where the first character of the captured substring was found.
C# Syntax:
public int Index {get;}

Return to top


Property: Length (read-only)
Inherited
See base class member description: System.Text.RegularExpressions.Capture.Length

Summary
The length of the captured substring.
C# Syntax:
public int Length {get;}

Return to top


Property: Success (read-only)
Inherited
See base class member description: System.Text.RegularExpressions.Group.Success

Summary
Gets a value indicating whether the match is successful.
C# Syntax:
public bool Success {get;}
Remarks
The Success property is true if at least one substring was captured by this group. It is equivalent to the Boolean expression (Group.Captures.Count > 0).

Return to top


Property: Value (read-only)
Inherited
See base class member description: System.Text.RegularExpressions.Capture.Value

Summary
Gets the captured substring from the input string.
C# Syntax:
public string Value {get;}

Return to top


Method: Equals(
   object obj
)
Inherited
See base class member description: System.Object.Equals
C# Syntax:
public virtual bool Equals(
   object obj
);

For more information on members inherited from System.Object click on the link above.

Return to top


Method: Finalize()
Inherited
See base class member description: System.Object.Finalize
C# Syntax:
~Match();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: GetHashCode()
Inherited
See base class member description: System.Object.GetHashCode
C# Syntax:
public virtual int GetHashCode();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: GetType()
Inherited
See base class member description: System.Object.GetType
C# Syntax:
public Type GetType();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: MemberwiseClone()
Inherited
See base class member description: System.Object.MemberwiseClone
C# Syntax:
protected object MemberwiseClone();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: NextMatch()
Summary
Returns a new Match with the results for the next match, starting at the position at which the last match ended (at the character beyond the last matched character).
C# Syntax:
public Match NextMatch();
Return Value:
The next regular expression Match object.
Remarks
This function is similar to calling Match again and passing (Index+Length) as the new starting position, but it differs from calling Match directly because it handles zero-length match cases in a way that guarantees progress to the end of the string.

Return to top


Method: Result(
   string replacement
)
Summary
Returns the expansion of the passed replacement pattern. For example, if the replacement pattern is $1$2, Result returns the concatenation of Groups[1].Value and Groups[2].Value (Groups(1).Value and Groups(2).Value).
C# Syntax:
public virtual string Result(
   string replacement
);
Parameters:

replacement

The replacement pattern to be used by the function.

Return Value:
The expanded version of replacement.

Return to top


Method: Synchronized(
   Match inner
)
Summary
Returns a Match instance equivalent to the one supplied that is safe to share between multiple threads.
C# Syntax:
public static Match Synchronized(
   Match inner
);
Parameters:

inner

A Match instance equivalent to the one expected.

Return Value:
A Match instance equivalent to the one supplied that is safe to share between multiple threads.

Return to top


Method: ToString()
Inherited
See base class member description: System.Text.RegularExpressions.Capture.ToString

Summary
Gets the captured substring from the input string.
C# Syntax:
public override string ToString();
Return Value:
The actual substring that was captured by the match.
Remarks
ToString is actually an internal call to Capture.Value.

Return to top


Top of page

Copyright (c) 2002 Microsoft Corporation. All rights reserved.