Skip to content

Instantly share code, notes, and snippets.

@millsy
Created May 10, 2012 22:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save millsy/2656429 to your computer and use it in GitHub Desktop.
Save millsy/2656429 to your computer and use it in GitHub Desktop.
Regex Collection Matching Example Split Email in C#
public string[] emailSplit(string email)
{
string[] result = null;
Regex exp = new Regex(@"^([^@]*)@(.*)", RegexOptions.IgnoreCase);
MatchCollection matches = exp.Matches(email);
if (matches.Count == 1 && matches[0].Groups.Count > 1)
{
Match m = matches[0];
result = new string[m.Groups.Count -1];
for (int i = 1; i < m.Groups.Count; i++)
{
result[i-1] = m.Groups[i].Value;
}
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment