Expression Archive Articles

Regex for a HTML tag

Regex for a HTML tag <.[^>]*> This can proove invaluable when you're wanting to replace keywords in HTML without spoiling the tags themselves. Particularly useful in SEO.

Paul Hayman - 2,891 views

Date Regular Expression (dd/MMM/yyyy)

Date Regular Expression (dd/MMM/yyyy) The following matches: 01/JAN/2007 22/Feb/2006 But doesn't match: 01/01/2007 22/02/2007 01 Jan 2007 ^(([0-9])|([0-2][0-9])|([3][0-1]))\/(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\/\d{4

Paul Hayman - 29,680 views

Hex code Regular Expression (#F0F0F0)

Hex code Regular Expression (#F0F0F0) The following matches valid HTML hexadecimal color codes. The # symbol is optional. It will except either the 3 digit form for the 216 Web safe colors, or the full 6 digit form. ^#?([a-f]|[A-F]|[0-9]){3}(([a-f]|[A-F]|[0-9]){3})?$

Paul Hayman - 16,700 views

Email Regex Pattern

Email Regex Pattern ^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$

Paul Hayman - 5,581 views

Time Regular Expression

Time Regular Expression ^([0-1][0-9]|[2][0-3]):([0-5][0-9])$ 

Paul Hayman - 4,973 views

ISBN Number regular expression

ISBN Number regular expression string pattern = @"ISBN\x20(?=.{13}$)\d{1,5}([- ])\d{1,7}\1\d{1,6}\1(\d|X)$"; Examples // Valid Console.WriteLine(Regex.IsMatch(@"ISBN 0 93028 923 4", @"ISBN\x20(?=.{13}$)\d{1,5}([- ])\d{1,7}\1\d{1,6}\1(\d|X)$

Paul Hayman - 11,511 views

IP Address regular expression

IP Address regular expression string pattern = @"\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b"  

Paul Hayman - 83,090 views

Email Address Regular Expression

Email Address Regular Expression string pattern = @"([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)"  

Paul Hayman - 4,514 views

Mail and News Regular Expression

Mail and News Regular Expression string pattern = @"(?<ignore>(^|\s|\W)[\W*])?(?<uri>((mailto|news){1}:[^(//\s,)][\w\d:#@%/;$()~_?\+-=\\\.&]+))"  

Paul Hayman - 3,660 views

URL Regular Expression

URL Regular Expression string pattern = @"((https?|ftp|gopher|telnet|file|notes|ms-help):((//)|(\\\\))+[\w\d:#@%/;$()~_?\+-=\\\.&]*)"  

Paul Hayman - 152,829 views

IsGuid() (Regular Expression Guid Match)

IsGuid() (Regular Expression Guid Match) A regular expression for validating a string as being a Guid is.. @"^(\{{0,1}([0-9a-fA-F]){8}-([0-9a-fA-F]){4}-([0-9a-fA-F]){4}-([0-9a-fA-F]){4}-([0-9a-fA-F]){12}\}{0,1})$" Example usage Below is a function I try to keep handy which t

Paul Hayman - 97,350 views