Regex.Split Method (String, String, RegexOptions)

Splits the input string at the positions defined by a specified regular expression pattern. Options can be specified to modify matching behavior.

Namespace: System.Text.RegularExpressions
Assembly: System (in system.dll)

public static string[] Split (
	string input,
	string pattern,
	RegexOptions options
public static String[] Split (
	String input, 
	String pattern, 
	RegexOptions options
public static function Split (
	input : String, 
	pattern : String, 
	options : RegexOptions
) : String[]



The string to split.


The regular expression defining to match.


A bitwise OR combination of RegexOption enumeration values.

Return Value

An array of strings.

The Regex.Split methods are similar to the Split method, except this method splits the string at a delimiter determined by a regular expression instead of a set of characters. If count is specified, the string is split into at most count strings (the last string containing the unsplit remainder of the string); a count value of zero provides the default behavior of splitting as many times as possible. If startat is specified, the first delimiter is searched for starting at the specified point (this can be used, for example, for skipping leading white space).

If capturing groups are used in a Regex.Split expression, the capturing groups are included in the resulting string array. The following example would yield the array items "one", "-", "two", "-", "banana".

 Regex r = new Regex("(-)"); // Split on hyphens.
 string[] s = r.Split("one-two-banana");

If the regular expression can match the empty string (for example, x*), Split will split the string into an array of single-character strings because the empty string delimiter can be found at every location.

The static Split methods are equivalent to constructing a Regex object with the specified regular expression pattern and calling the instance method Split. The static methods are provided to allow an isolated, single use of a regular expression without explicitly creating a Regex object.

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

Community Additions