Regex.Split Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Splits an input string into an array of substrings at the positions defined by a regular expression match.
Overloads
| Name | Description |
|---|---|
| Split(String, String, RegexOptions, TimeSpan) |
Splits an input string into an array of substrings at the positions defined by a specified regular expression pattern. Additional parameters specify options that modify the matching operation and a time-out interval if no match is found. |
| Split(String, String, RegexOptions) |
Splits an input string into an array of substrings at the positions defined by a specified regular expression pattern. Specified options modify the matching operation. |
| Split(String, Int32, Int32) |
Splits an input string a specified maximum number of times into an array of substrings, at the positions defined by a regular expression specified in the Regex constructor. The search for the regular expression pattern starts at a specified character position in the input string. |
| Split(String, String) |
Splits an input string into an array of substrings at the positions defined by a regular expression pattern. |
| Split(String) |
Splits an input string into an array of substrings at the positions defined by a regular expression pattern specified in the Regex constructor. |
| Split(String, Int32) |
Splits an input string a specified maximum number of times into an array of substrings, at the positions defined by a regular expression specified in the Regex constructor. |
Split(String, String, RegexOptions, TimeSpan)
- Source:
- Regex.Split.cs
- Source:
- Regex.Split.cs
- Source:
- Regex.Split.cs
- Source:
- Regex.Split.cs
- Source:
- Regex.Split.cs
Splits an input string into an array of substrings at the positions defined by a specified regular expression pattern. Additional parameters specify options that modify the matching operation and a time-out interval if no match is found.
public:
static cli::array <System::String ^> ^ Split(System::String ^ input, System::String ^ pattern, System::Text::RegularExpressions::RegexOptions options, TimeSpan matchTimeout);
public static string[] Split(string input, string pattern, System.Text.RegularExpressions.RegexOptions options, TimeSpan matchTimeout);
static member Split : string * string * System.Text.RegularExpressions.RegexOptions * TimeSpan -> string[]
Public Shared Function Split (input As String, pattern As String, options As RegexOptions, matchTimeout As TimeSpan) As String()
Parameters
- input
- String
The string to split.
- pattern
- String
The regular expression pattern to match.
- options
- RegexOptions
A bitwise combination of the enumeration values that provide options for matching.
- matchTimeout
- TimeSpan
A time-out interval, or InfiniteMatchTimeout to indicate that the method should not time out.
Returns
An array of strings.
Exceptions
A regular expression parsing error occurred.
input or pattern is null.
options is not a valid bitwise combination of
RegexOptions values.
-or-
matchTimeout is negative, zero, or greater than approximately 24 days.
A time-out occurred.
Remarks
The static Split(String, String, RegexOptions, TimeSpan) methods are equivalent to constructing a Regex object with the specified regular expression pattern and calling the instance method Split(String).
The Regex.Split methods are similar to the Split(Char[]) method, except that Regex.Split splits the string at a delimiter determined by a regular expression instead of a set of characters. If the regular expression pattern includes capturing parentheses, the captured text is included in the resulting string array. If the pattern includes capturing parentheses, any captured text is included in the resulting string array, but is not counted when determining whether the count limit has been reached.
If two adjacent matches are found, an empty string is placed in the array.
If you specify RightToLeft for the options parameter, the search for matches begins at the end of the input string and moves left.
The matchTimeout parameter specifies how long a pattern matching method should try to find a match before it times out. matchTimeout overrides any default time-out value defined for the application domain in which the method executes.
Notes to Callers
We recommend that you set the matchTimeout parameter to an appropriate value, such as two seconds. If you disable time-outs by specifying InfiniteMatchTimeout, the regular expression engine offers slightly better performance. However, you should disable time-outs only under the following conditions:
When the input processed by a regular expression is derived from a known and trusted source or consists of static text. This excludes text that has been dynamically input by users.
When the regular expression pattern has been thoroughly tested to ensure that it efficiently handles matches, non-matches, and near matches.
When the regular expression pattern contains no language elements that are known to cause excessive backtracking when processing a near match.
See also
Applies to
Split(String, String, RegexOptions)
- Source:
- Regex.Split.cs
- Source:
- Regex.Split.cs
- Source:
- Regex.Split.cs
- Source:
- Regex.Split.cs
- Source:
- Regex.Split.cs
Splits an input string into an array of substrings at the positions defined by a specified regular expression pattern. Specified options modify the matching operation.
public:
static cli::array <System::String ^> ^ Split(System::String ^ input, System::String ^ pattern, System::Text::RegularExpressions::RegexOptions options);
public static string[] Split(string input, string pattern, System.Text.RegularExpressions.RegexOptions options);
static member Split : string * string * System.Text.RegularExpressions.RegexOptions -> string[]
Public Shared Function Split (input As String, pattern As String, options As RegexOptions) As String()
Parameters
- input
- String
The string to split.
- pattern
- String
The regular expression pattern to match.
- options
- RegexOptions
A bitwise combination of the enumeration values that provide options for matching.
Returns
An array of strings.
Exceptions
A regular expression parsing error occurred.
input or pattern is null.
options is not a valid bitwise combination of
RegexOptions values.
A time-out occurred.
Remarks
The static Split(String, String, RegexOptions) methods are equivalent to constructing a Regex object with the specified regular expression pattern and calling the instance method Split(String).
The Regex.Split methods are similar to the Split(Char[]) method, except that Regex.Split splits the string at a delimiter determined by a regular expression instead of a set of characters. If the regular expression pattern includes capturing parentheses, the captured text is included in the resulting string array. If the pattern includes capturing parentheses, any captured text is included in the resulting string array, but is not counted when determining whether the count limit has been reached.
If two adjacent matches are found, an empty string is placed in the array.
If you specify RightToLeft for the options parameter, the search for matches begins at the end of the input string and moves left.
Notes to Callers
This method times out after an interval that is equal to the default time-out value of the application domain in which the method is called. If a time-out value has not been defined for the application domain, the value InfiniteMatchTimeout, which prevents the method from timing out, is used. The recommended static method for splitting text on a pattern match is Split(String, String, RegexOptions, TimeSpan), which lets you set the time-out interval.
See also
Applies to
Split(String, Int32, Int32)
- Source:
- Regex.Split.cs
- Source:
- Regex.Split.cs
- Source:
- Regex.Split.cs
- Source:
- Regex.Split.cs
- Source:
- Regex.Split.cs
Splits an input string a specified maximum number of times into an array of substrings, at the positions defined by a regular expression specified in the Regex constructor. The search for the regular expression pattern starts at a specified character position in the input string.
public:
cli::array <System::String ^> ^ Split(System::String ^ input, int count, int startat);
public string[] Split(string input, int count, int startat);
member this.Split : string * int * int -> string[]
Public Function Split (input As String, count As Integer, startat As Integer) As String()
Parameters
- input
- String
The string to split.
- count
- Int32
The maximum number of times the split can occur.
- startat
- Int32
The character position in the input string where the search begins.
Returns
An array of strings.
Exceptions
input is null.
startat is less than zero or greater than the length of
input.
A time-out occurred.
Remarks
For more details about startat, see the Remarks section of Match(String, Int32).
If capturing parentheses are used in the expression, any captured text is included in the resulting string array but is not counted toward the count limit.
Empty strings that result from adjacent matches are counted when determining whether the number of matches has reached count.
See also
Applies to
Split(String, String)
- Source:
- Regex.Split.cs
- Source:
- Regex.Split.cs
- Source:
- Regex.Split.cs
- Source:
- Regex.Split.cs
- Source:
- Regex.Split.cs
Splits an input string into an array of substrings at the positions defined by a regular expression pattern.
public:
static cli::array <System::String ^> ^ Split(System::String ^ input, System::String ^ pattern);
public static string[] Split(string input, string pattern);
static member Split : string * string -> string[]
Public Shared Function Split (input As String, pattern As String) As String()
Parameters
- input
- String
The string to split.
- pattern
- String
The regular expression pattern to match.
Returns
An array of strings.
Exceptions
A regular expression parsing error occurred.
input or pattern is null.
A time-out occurred.
Remarks
The static Split(String, String) methods are equivalent to constructing a Regex object with the specified regular expression pattern and calling the instance method Split(String).
The Regex.Split methods are similar to the Split(Char[]) method, except that Regex.Split splits the string at a delimiter determined by a regular expression instead of a set of characters. If the regular expression pattern includes capturing parentheses, the captured text is included in the resulting string array. If the pattern includes capturing parentheses, any captured text is included in the resulting string array, but is not counted when determining whether the count limit has been reached.
If two adjacent matches are found, an empty string is placed in the array.
Notes to Callers
This method times out after an interval that is equal to the default time-out value of the application domain in which the method is called. If a time-out value has not been defined for the application domain, the value InfiniteMatchTimeout, which prevents the method from timing out, is used. The recommended static method for splitting text on a pattern match is Split(String, String, RegexOptions, TimeSpan), which lets you set the time-out interval.
See also
Applies to
Split(String)
- Source:
- Regex.Split.cs
- Source:
- Regex.Split.cs
- Source:
- Regex.Split.cs
- Source:
- Regex.Split.cs
- Source:
- Regex.Split.cs
Splits an input string into an array of substrings at the positions defined by a regular expression pattern specified in the Regex constructor.
public:
cli::array <System::String ^> ^ Split(System::String ^ input);
public string[] Split(string input);
member this.Split : string -> string[]
Public Function Split (input As String) As String()
Parameters
- input
- String
The string to split.
Returns
An array of strings.
Exceptions
input is null.
A time-out occurred.
Remarks
The Regex.Split methods are similar to the Split(Char[]) method, except that Regex.Split splits the string at a delimiter determined by a regular expression instead of a set of characters. The string is split as many times as possible. If no match is found, the return value contains one element whose value is the original input string.
If the regular expression can match the empty string, Split(String) will split the string into an array of single-character strings because the empty string delimiter can be found at every location.
If capturing parentheses are used in the expression, any captured text is included in the resulting string array.
If two adjacent matches are found, an empty string is placed in the array.
See also
Applies to
Split(String, Int32)
- Source:
- Regex.Split.cs
- Source:
- Regex.Split.cs
- Source:
- Regex.Split.cs
- Source:
- Regex.Split.cs
- Source:
- Regex.Split.cs
Splits an input string a specified maximum number of times into an array of substrings, at the positions defined by a regular expression specified in the Regex constructor.
public:
cli::array <System::String ^> ^ Split(System::String ^ input, int count);
public string[] Split(string input, int count);
member this.Split : string * int -> string[]
Public Function Split (input As String, count As Integer) As String()
Parameters
- input
- String
The string to split.
- count
- Int32
The maximum number of times the split can occur.
Returns
An array of strings.
Exceptions
input is null.
A time-out occurred.
Remarks
The Regex.Split methods are similar to Split(Char[]). The count parameter specifies the maximum number of substrings into which the input string can be split; the last string contains the unsplit remainder of the string. A count value of zero provides the default behavior of splitting as many times as possible.
If capturing parentheses are used in the expression, any captured text is included in the resulting string array but is not counted toward the count limit.
Empty strings that result from adjacent matches are counted when determining whether the number of matches has reached count.