Regex::Match Method (String, Int32, Int32)
Searches the input string for the first occurrence of a regular expression, beginning at the specified starting position and searching only the specified number of characters.
Assemblies: System.Text.RegularExpressions (in System.Text.RegularExpressions.dll)
System (in System.dll)
- Type: System::String
The string to search for a match.
- Type: System::Int32
The zero-based character position in the input string that defines the leftmost position to be searched.
- Type: System::Int32
The number of characters in the substring to include in the search.
Return ValueType: System.Text.RegularExpressions::Match
An object that contains information about the match.
input is nullptr.
beginning is less than zero or greater than the length of input.
length is less than zero or greater than the length of input.
beginning + length – 1 identifies a position that is outside the range of input.
A time-out occurred. For more information about time-outs, see the Remarks section.
The method returns the first substring that matches a regular expression pattern in a portion of an input string. For information about the language elements used to build a regular expression pattern, see Regular Expression Language - Quick Reference.
The regular expression pattern for which the method searches is defined by the call to one of the Regex class constructors. For more information about the elements that can form a regular expression pattern, see Regular Expression Language - Quick Reference.
The method searches the portion of input defined by the beginning and length parameters for the regular expression pattern. beginning always defines the index of the leftmost character to include in the search, and length defines the maximum number of characters to search. Together, they define the range of the search. If the search proceeds from left to right (the default), the regular expression engine searches from the character at index beginning to the character at index beginning + length – 1. If the regular expression engine was instantiated by using the RegexOptions::RightToLeft option so that the search proceeds from right to left, the regular expression engine searches from the character at index beginning + length – 1 to the character at index beginning. This method returns the first match that it finds within this range. You can retrieve subsequent matches by repeatedly calling the returned Match object's Match::NextMatch method.
You can determine whether the regular expression pattern has been found in the input string by checking the value of the returned Match object's Success property. If a match is found, the returned Match object's Value property contains the substring from input that matches the regular expression pattern. If no match is found, its value is String::Empty.
The RegexMatchTimeoutException exception is thrown if the execution time of the matching operation exceeds the time-out interval specified by the Regex::Regex(String, RegexOptions, TimeSpan) constructor. If you do not set a time-out value when you call the constructor, the exception is thrown if the operation exceeds any time-out value established for the application domain in which the Regex object is created. If no time-out is defined in the Regex constructor call or in the application domain's properties, or if the time-out value is Regex::InfiniteMatchTimeout, no exception is thrown.
.NET FrameworkSupported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0
.NET Framework Client ProfileSupported in: 4, 3.5 SP1
Portable Class LibrarySupported in: Portable Class Library
.NET for Windows Store appsSupported in: Windows 8
Supported in: Windows Phone 8.1
Supported in: Windows Phone Silverlight 8.1
Supported in: Windows Phone Silverlight 8
Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)