 |
Regex for a HTML tag
Paul Hayman (701 views)
Regex for a HTML tag
#c#<.[^>]*>
This can proove invaluable when you're wanting to replace keywords in HTML without spoiling the tags themselves. Particularly useful in SEO.
|
 |
Date Regular Expression (dd/MMM/yyyy)
Paul Hayman (1230 views)
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
#c#^(([0-9])|([0-2][0-9])|([3][0-1]))\/(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\/\d{4}$
|
 |
Hex code Regular Expression (#F0F0F0)
Paul Hayman (1437 views)
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.
#c#^#?([a-f]|[A-F]|[0-9]){3}(([a-f]|[A-F]|[0-9]){3})?$
|
 |
Email Regex Pattern
Paul Hayman (575 views)
Email Regex Pattern
#c#^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$
|
 |
Time Regular Expression
Paul Hayman (539 views)
Time Regular Expression
#c#^([0-1][0-9]|[2][0-3]):([0-5][0-9])$
|
 |
ISBN Number regular expression
Paul Hayman (2586 views)
ISBN Number regular expression
#c#string pattern = @"ISBN\x20(?=.{13}$)\d{1,5}([- ])\d{1,7}\1\d{1,6}\1(\d|X)$";
Examples
#c#// Valid
#c#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)$"));
#c#
#c#// Valid
#c#Console.Wr
|
 |
IP Address regular expression
Paul Hayman (9754 views)
IP Address regular expression
#c#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"
#c#
|
 |
Email Address Regular Expression
Paul Hayman (1919 views)
Email Address Regular Expression
#c#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})(\]?)"
#c#
|
 |
Mail and News Regular Expression
Paul Hayman (1009 views)
Mail and News Regular Expression
#c#string pattern = @"(?<ignore>(^|\s|\W)[\W*])?(?<uri>((mailto|news){1}:[^(//\s,)][\w\d:#@%/;$()~_?\+-=\\\.&]+))"
#c#
|
 |
URL Regular Expression
Paul Hayman (12980 views)
URL Regular Expression
#c#string pattern = @"((https?|ftp|gopher|telnet|file|notes|ms-help):((//)|(\\\\))+[\w\d:#@%/;$()~_?\+-=\\\.&]*)"
#c#
|
 |
IsGuid() (Regular Expression Guid Match)
Paul Hayman (9940 views)
IsGuid() (Regular Expression Guid Match)
A regular expression for validating a string as being a Guid is..
#c#@"^(\{{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})$"
#c#
Example usage
Below is a function I try to keep handy which tests
|