Friday, 31 May 2013

Regex to match 1,4;5;22,6;63...

This regex will match comma delimited pairs of integers delimited by semicolon, while upper limit is set to 10000

^([1-9]\d{0,3}|10000),([1-9]\d{0,3}|10000)(;([1-9]\d{0,3}|10000),([1-9]\d{0,3}|10000))*,*$

Thursday, 30 May 2013

Email regex expression

\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*

Redirecting domain.com to www.domain.com


In global.asax:


protected void Application_BeginRequest(Object sender, EventArgs e)
{
    if (Request.Url.Authority.StartsWith("www"))
        return;

    string url = (Request.Url.Scheme
       + "://www."
       + HttpContext.Current.Request.Url.Authority
       + HttpContext.Current.Request.Url.AbsolutePath
    );

    Response.Clear();
    Response.Status = "301 Moved Permanently";
    Response.AddHeader("Location", url);
    Response.End();
}

Source: stackoverflow

Swapping two strings in Excel cell

Strings must be delimited with space e.g. "John Doe"

=TRIM(MID(A2,FIND(" ",A2)+1,1000))&" "&LEFT(A2,FIND(" ",A2)-1)