View All Blog Posts

Using Regular Expressions with Data Sync

This is a real quick example of how to use a regular expression with Data Sync 3.0 Dynamic Columns to extract the Domain Name from a users Email address.

Dynamic Columns

Dynamic Column Code

class DataSourceRowOverride : DataSourceRowInternal
{    
    public string EmailDomain { get { return GetDomainName(Email); } }
        
    public string GetDomainName(string value) 
    {
        var expression = new Regex(@"[A-Z0-9._%-]+@([A-Z0-9.-]+\.[A-Z]{2,4})", RegexOptions.IgnoreCase);
        
        var match = expression.Match(value);
        if ( match.Success )
            return match.Result("$1");
            
        return value;
    }
}
| Tuesday, January 4, 2011 |