Parsing an email string My program needs to parse an e-mail string. There are two possibilities to enter an e-mail-address. Either with the alias or without one, plain the e-mail-address.

1st possibity:  

string addressWithAlias = "test my address &lt;bla@blub.com&gt;";


2nd possibility:

string addressWithoutAlias = "bla@blub.com";


So, I wrote two functions:

private static string[] getAddressPartsRegex(string address)
{
    string plainaddress = address.Trim();

    Regex reg = new Regex(@"(.+?(?=&lt;))&lt;(.*@.*?)&gt;");
    var gr = reg.Match(plainaddress).Groups;

    return gr.Count == 1 
        ? new[] { plainaddress } 
        : new[] { gr[1].Value.Trim(), gr[2].Value.Trim() };
}

private static string[] getAddressParts(string address)
{
    var splittedAdress = address.Split(' ');
    return splittedAdress.Last().Trim().StartsWith("&lt;") 
        ? new[] { string.Join(" ", splittedAdress.Take(splittedAdress.Length - 1)), splittedAdress.Last().Trim(' ', '&lt;', '&gt;') }
        : splittedAdress;
}


They both work fine and the results are the same. One uses regex, the other uses Split and Join. 
What would you suggest to use, and why? What is the more beautiful function?
Are there any bugs I didn't see?
Consider taking advantage of existing features that could provide an additional layer of validation.

mainly System.Net.Mail.MailAddress

Also as mentioned in a comment, no need to be creating the regular expression every time the function is called.

static Regex mailExpression = new Regex(@"(.+?(?=&lt;))&lt;(.*@.*?)&gt;");
private static MailAddress getAddress(string address) {
    if (address == null) throw new ArgumentNullException("address");
    if (string.IsNullOrWhiteSpace(address)) throw new ArgumentException("invalid address", "address");

    var plainaddress = address.Trim();
    var groups = mailExpression.Match(plainaddress).Groups;

    return groups.Count == 1
        ? new MailAddress(plainaddress)
        : new MailAddress(groups[2].Value.Trim(), groups[1].Value.Trim());
}


According to reference source code, internally MailAddress will try to parse the address given to it.

This avoids having to roll your own parser as one already exists out of the box that has been tried, tested and is stable.

private static MailAddress getAddress(string address) {
    if (address == null) throw new ArgumentNullException("address");
    if (string.IsNullOrWhiteSpace(address)) throw new ArgumentException("invalid address", "address");

    address = address.Trim();
    return new MailAddress(address);
}


You have the added advantage of having a strongly typed object model to work with that will provide you with usable properties.

The following Unit Test demonstrates the desired behavior.

[TestClass]
public class EmailParserTest {
    [TestMethod]
    public void Should_Parse_EmailAddress_With_Alias() {
        //Arrange
        var expectedAlias = "test my address";
        var expectedAddress = "bla@blub.com";
        string addressWithAlias = "test my address &lt;bla@blub.com&gt;";

        //Act
        var mailAddressWithAlias = getAddress(addressWithAlias);

        //Assert
        mailAddressWithAlias
            .Should()
            .NotBeNull()
            .And.Match&lt;MailAddress&gt;(_ =&gt; _.Address == expectedAddress &amp;&amp; _.DisplayName == expectedAlias);

    }

    [TestMethod]
    public void Should_Parse_EmailAddress_Without_Alias() {
        //Arrange
        var addressWithoutAlias = "bla@blub.com";

        //Act
        var mailAddressWithoutAlias = getAddress(addressWithoutAlias);

        //Assert
        mailAddressWithoutAlias
            .Should()
            .NotBeNull()
            .And.Match&lt;MailAddress&gt;(_ =&gt; _.Address == addressWithoutAlias &amp;&amp; _.DisplayName == string.Empty);
        ;
    }

    private static MailAddress getAddress(string address) {
        if (address == null) throw new ArgumentNullException("address");
        if (string.IsNullOrWhiteSpace(address)) throw new ArgumentException("invalid address", "address");

        address = address.Trim();
        return new MailAddress(address);
    }
}