Created
May 10, 2012 22:52
-
-
Save millsy/2656429 to your computer and use it in GitHub Desktop.
Regex Collection Matching Example Split Email in C#
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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