How to

split text using regular expresions

Published: 24. October 2011 | Updated: 26. October 2011
License: Microsoft Public License (MS-PL)
Categories: Framework » Regex
Tags: C# Regex Text
Was this snippet helpful for you? YESYES / NONO

Import namespace

using System.Text.RegularExpressions;

Code

string input = "abc-def;ghi+jkl";
string pattern = @"[;\-\,\+]";

string[] splitted = Regex.Split(input, pattern);

foreach (string item in splitted)
{
    Console.WriteLine(item);
}
Console Output:
abc
def
ghi
jkl
Send us feedback about this snippet »



Related Snippets: