RegExLib.com - The first Regular Expression Library on the Web!

Please support RegExLib Sponsors

Sponsors

Expressions by User

Change page:   |    Displaying page 1 of 2 pages; Items 1 to 20
Title Test Details URL Validator
Expression
^(http(?:s)?\:\/\/[a-zA-Z0-9]+(?:(?:\.|\-)[a-zA-Z0-9]+)+(?:\:\d+)?(?:\/[\w\-]+)*(?:\/?|\/\w+\.[a-zA-Z]{2,4}(?:\?[\w]+\=[\w\-]+)?)?(?:\&[\w]+\=[\w\-]+)*)$
Description
A simple but powerful URL validating regex. Accepts multiple sub-domains and sub-directories. Even accept query strings. Now accept ports! Accepts HTTP or HTTPS. Also accepts optional "/" on end of address.
Matches
http://website.com | http://subdomain.web-site.com/cgi-bin/perl.cgi?key1=value1&key2=value2
Non-Matches
http://website.com/perl.cgi?key= | http://web-site.com/cgi-bin/perl.cgi?key1=value1&key2
Author Rating: The rating for this expression. tedcambron
Title Test Details Email Validator
Expression
^([a-zA-Z0-9]+(?:[.-]?[a-zA-Z0-9]+)*@[a-zA-Z0-9]+(?:[.-]?[a-zA-Z0-9]+)*\.[a-zA-Z]{2,7})$
Description
After reading RFC2822 (then taking two asprin) I've come to the conclusion that I will not allow all RFC compliant email addresses to be entered in the forms on my website and will never have an issue with it. I demand a stricter tolerance for my website than RFC allows. If you're like me and only want to allow 99% of those email addresses entered into web-forms then use this little gem of an email checking regex. Also, I've never met anyone who would submit an email address taking full advantage of RFC2822's allowances nor would I care to accommodate one who would.
Matches
Non-Matches
Author Rating: The rating for this expression. tedcambron
Title Test Details Image URL
Expression
^(http\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(?:\/\S*)?(?:[a-zA-Z0-9_])+\.(?:jpg|jpeg|gif|png))$
Description
A nice little regex to verify a URL pointing towards an image. Can be useful.
Matches
http://website.com/directory/image.gif
Non-Matches
www.website.com/image.php
Author Rating: Not yet rated. tedcambron
Title Test Details Query String Regex
Expression
^((?:\?[a-zA-Z0-9_]+\=[a-zA-Z0-9_]+)?(?:\&[a-zA-Z0-9_]+\=[a-zA-Z0-9_]+)*)$
Description
This is a very simple regex that check the query part of a string. That is to say anything after the "?" at the end of an URL.
Matches
?key=value | ?key1=value1&key2=value2
Non-Matches
key=value | ?key=value&
Author Rating: The rating for this expression. tedcambron
Title Test Details Absolute Path
Expression
^((?:\/[a-zA-Z0-9]+(?:_[a-zA-Z0-9]+)*(?:\-[a-zA-Z0-9]+)*)+)$
Description
An overly simple UNIX based path regex. The path must begin with a forward slash. The path segments may not lead or end with an underscore or dash which is a good thing. They also can not be doubled (__ or --). Another good thing. I've omitted all the punctuation that RFC allows until further notice.
Matches
/users/web/mysite/web/cgi-bin
Non-Matches
/users/web/my site/web/cgi-bin | users/web/mysite/web/cgi-bin/
Author Rating: The rating for this expression. tedcambron
Title Test Details Basic Subject or Title
Expression
^([a-zA-Z0-9]+(?: [a-zA-Z0-9]+)*)$
Description
This is a very basic regex for a simple subject or title. It must begin and end with a word character and may contain spaces. No punctuation :(
Matches
My Category
Non-Matches
any nonword character and leading/trailing spaces
Author Rating: The rating for this expression. tedcambron
Title Test Details RFC Compliant Path
Expression
^(/(?:(?:(?:(?:[a-zA-Z0-9\\-_.!~*'():\@&=+\$,]+|(?:%[a-fA-F0-9][a-fA-F0-9]))*)(?:;(?:(?:[a-zA-Z0-9\\-_.!~*'():\@&=+\$,]+|(?:%[a-fA-F0-9][a-fA-F0-9]))*))*)(?:/(?:(?:(?:[a-zA-Z0-9\\-_.!~*'():\@&=+\$,]+|(?:%[a-fA-F0-9][a-fA-F0-9]))*)(?:;(?:(?:[a-zA-Z0-9\\-_.!~*'():\@&=+\$,]+|(?:%[a-fA-F0-9][a-fA-F0-9]))*))*))*))$
Description
After reading RFC2396 and researching it a little more I put together this regex to use for verifying a path rather than my non-compliant, safer, overly simple one. More specifically an absolute path.
Matches
All RFC2396 compliant paths
Non-Matches
A non-RFC2396 compliant path
Author Rating: Not yet rated. tedcambron
Title Test Details US Phone Number
Expression
^(1?(?: |\-|\.)?(?:\(\d{3}\)|\d{3})(?: |\-|\.)?\d{3}(?: |\-|\.)?\d{4})$
Description
This is my simple phone number regex. There are many like it but this is mine. It accepts the most common United States phone number formats that normal people use. The number 1 at the beginning is optional and so is the separators. The separators can be a dash (-), a period (.) or a space. Putting the area code in parenthesis is also an option. That's about it.
Matches
1-234-567-8910 | (123) 456-7891 | 123.456.7891 | 12345678910
Non-Matches
12-345-678-9101 | 123-45678 | 123456789101
Author Rating: The rating for this expression. tedcambron
Title Test Details US Zip Code
Expression
^(\d{5}(?:\-\d{4})?)$
Description
Just for US zip codes. Very simple but effective regex for verifying a number that resembles a zip code. The post office number is optional.
Matches
12345 | 12345-6789
Non-Matches
1234 | 123456 | 12345-123 | 12345-12345
Author Rating: The rating for this expression. tedcambron
Title Test Details Social Security Number
Expression
^(?!000)(?!666)(?!9)\d{3}([- ]?)(?!00)\d{2}\1(?!0000)\d{4}$
Description
Updated SSN regex. A very simple one for verifying a properly formatted US social security number. First three digits must be 001 - 899 and not 666. Disallows all zeros in a group.
Matches
123-45-6789
Non-Matches
123-45 6789 | 1234-56-7890 | 123-00-7890
Author Rating: The rating for this expression. tedcambron
Title Test Details Date
Expression
^(\d{4}(?:(?:(?:\-)?(?:00[1-9]|0[1-9][0-9]|[1-2][0-9][0-9]|3[0-5][0-9]|36[0-6]))?|(?:(?:\-)?(?:1[0-2]|0[1-9]))?|(?:(?:\-)?(?:1[0-2]|0[1-9])(?:\-)?(?:0[1-9]|[12][0-9]|3[01]))?|(?:(?:\-)?W(?:0[1-9]|[1-4][0-9]5[0-3]))?|(?:(?:\-)?W(?:0[1-9]|[1-4][0-9]5[0-3])(?:\-)?[1-7])?)?)$
Description
This is a regular expression to check for a properly formatted date according to the international date and time notation ISO 8601. Remember, this is just for the date. See ISO 8601 specification for more information.
Matches
ISO 8601 date format
Non-Matches
non-ISO date format
Author Rating: The rating for this expression. tedcambron
Title Test Details Time
Expression
^([0-2][0-4](?:(?:(?::)?[0-5][0-9])?|(?:(?::)?[0-5][0-9](?::)?[0-5][0-9](?:\.[0-9]+)?)?)?)$
Description
This is a regular expression to check for a properly formatted time according to the international date and time notation ISO 8601. See ISO 8601 specification for more information.
Matches
24 | 24:00 | 23:59:59 | 235959
Non-Matches
25 | 24:60
Author Rating: The rating for this expression. tedcambron
Title Test Details Class A Network Number
Expression
^(10\.[0-9]|[1-9][0-9]|[1-2][0-5][0-5]\.[0-9]|[1-9][0-9]|[1-2][0-5][0-5]\.[0-9]|[1-9][0-9]|[1-2][0-5][0-5])$
Description
The IANA resrved 24-bit block of IP address space for private internets. It's just a single class A network number. This is also RFC 1918 compliant.
Matches
10.0.0.0 | 10.255.255.255
Non-Matches
17.16.0.0 | 192.168.255.255
Author Rating: Not yet rated. tedcambron
Title Test Details Class B Network Numbers
Expression
^(172\.1[6-9]|2[0-9]|3[0-1|\.[0-9]|[1-9][0-9]|[1-2][0-5][0-5]\.[0-9]|[1-9][0-9]|[1-2][0-5][0-5])$
Description
This is a set of 16 contiguous class B network numbers or a 16-bit block of ip address space as reserved by the IANA. RFC 1918 compliant.
Matches
172.16.0.0 | 172.31.255.255
Non-Matches
10.0.0.0 | 10.255.255.255 | 192.168.0.0 | 192.168.255.255
Author Rating: Not yet rated. tedcambron
Title Test Details Class C Network Numbers
Expression
^(192\.168\.[0-9]|[1-9][0-9]|[1-2][0-5][0-5]\.[0-9]|[1-9][0-9]|[1-2][0-5][0-5])$
Description
This is the 16-bit block of the IP address space for private internets reserved by the IANA. A set of 256 contiguous class C network numbers per RFC 1918.
Matches
192.168.0.0 | 192.168.255.255
Non-Matches
10.0.0.0 | 172.31.255.255
Author Rating: Not yet rated. tedcambron
Title Test Details Punctuation
Expression
^((\'|\")?[a-zA-Z]+(?:\-[a-zA-Z]+)?(?:s\'|\'[a-zA-Z]{1,2})?(?:(?:(?:\,|\.|\!|\?)?(?:\2)?)|(?:(?:\2)?(?:\,|\.|\!|\?)?))(?: (\'|\")?[a-zA-Z]+(?:\-[a-zA-Z]+)?(?:s\'|\'[a-zA-Z]{1,2})?(?:(?:(?:\,|\.|\!|\?)?(?:\2|\3)?)|(?:(?:\2|\3)?(?:\,|\.|\!|\?)?)))*)$
Description
This is a little goofy regex to allow punctuation. I was reluctant to post it but what the heck. If it puts a smile on somebody's face then it was worth it. It works in most cases. :)
Matches
"hello!" | "hello again"! | I'm back
Non-Matches
hello" | "hello again!"! | I'mnot back
Author Rating: The rating for this expression. tedcambron
Title Test Details Embedded YouTube Video
Expression
(\"http:\/\/www\.youtube\.com\/v\/\w{11}\&rel\=1\")
Description
A simple regex to validate an embedded YouTube video.
Matches
a valid embedded YouTube video
Non-Matches
anything else
Author Rating: The rating for this expression. tedcambron
Title Test Details Embedded Google Video
Expression
(\"http:\/\/video\.google\.com\/googleplayer\.swf\?docId=\d{19}\&hl=[a-z]{2}\")
Description
A simple regex for validating an embedded Google video.
Matches
an embedded Google video
Non-Matches
anything else
Author Rating: The rating for this expression. tedcambron
Title Test Details Password
Expression
^([a-zA-Z0-9]{6,18}?)$
Description
My simple but effective password regex. The password can only contain letters and/or digits and must be at least 6 characters long and no more than 20. I know it says {6,18} but it just works out that way. The question mark was added for optimization. Also, the password can not begin or end with a space or underscore.
Matches
abc123
Non-Matches
_abc123_
Author Rating: The rating for this expression. tedcambron
Title Test Details Person's Name
Expression
^([a-zA-Z]+(?:\.)?(?:(?:'| )[a-zA-Z]+(?:\.)?)*)$
Description
Here's a regex for a person's name. Simple but effective.
Matches
Mr. O'Donnell III | Billy B. Bob Jr.
Non-Matches
@$%&? | 0'Donnell
Author Rating: The rating for this expression. tedcambron
Title Test Details Subject or Title w/ Punctuation
Expression
^([^_][\w\d\@\-]+(?:s\'|\'[a-zA-Z]{1,2})?(?:\,)?(?: [\w\d\@\-]+(?:s\'|\'[a-zA-Z]{1,2})?(?:\,)?)*(?:\.|\!|\?){0,3}[^\s_])$
Description
Here's a regex for a title or subject line. The title (or subject) may contain basic punctuation and may not have leading or trailing spaces or underscores but that's about it.
Matches
Wow, what a day! | 100th Aniversary | This Works...
Non-Matches
!Wow,what a night | _begin_ | This ,wont work' either....
Author Rating: Not yet rated. tedcambron
Title Test Details Numbers
Expression
^((?:\+|\-|\$)?(?:\d+|\d{1,3}(?:\,\d{3})*)(?:\.\d+)?(?:[a-zA-Z]{2}|\%)?)$
Description
Here's another one for numbers. Any kind of number. Money $$$, percentage %, ect. Commas are optional and must be properly formatted.
Matches
$1,000,000.00 | 100% | 12345.67890
Non-Matches
$$10.00 | 10%% | 1234,5678, | 123.456.789
Author Rating: The rating for this expression. tedcambron
Title Test Details Domain URL
Expression
^(http\:\/\/(?:www\.)?[a-zA-Z0-9]+(?:(?:\-|_)[a-zA-Z0-9]+)*(?:\.[a-zA-Z0-9]+(?:(?:\-|_)[a-zA-Z0-9]+)*)*\.[a-zA-Z]{2,7}(?:\/)?)$
Description
A URL to a domain name. Only for HTTP but that can be easily changed to accept more. The dashes and underscores can only be used between text and/or digits. The slash on the end is optional. Unlike my other URL checkers this one does not allow query strings.
Matches
http://www.website.com/ | http://my-website.net | http://another_site.org
Non-Matches
www.website.com | http://_website.com | http://www. web--site.com
Author Rating: The rating for this expression. tedcambron
Title Test Details Randal L. Schwartz
Expression
^(Randal (?:L\.)? Schwartz|merlyn)$
Description
This regex looks for Randal.
Matches
Randal L. Schwartz | merlyn
Non-Matches
Randy Smith | Arthur
Author Rating: Not yet rated. tedcambron
Title Test Details URL Segments
Expression
(?:[a-zA-Z0-9]+(?:(?:_|\-|\.)[a-zA-Z0-9]+)*)
Description
This is an expression I sometimes use to verify segments in a URL or directory path. It must begin and end with a word character and may contain "_" "-" and "." one at a time. It's non-capturing as it sits. More restrictive than RFC2396 and used to prevent directory transversal holes.
Matches
abc-123 | abc.def.ghi | my_path
Non-Matches
_abc | abc..123 | -my_path
Author Rating: Not yet rated. tedcambron
Title Test Details Domain Name
Expression
(?:[^0-9][a-zA-Z0-9]+(?:(?:\-|\.)[a-zA-Z0-9]+)*)
Description
This is a little regex to verify domain style names per RFC952. This is also found in RFC1034 and both use the terms domain name and host name interchangeably even though I believe there may be a difference. Only alpha, digit, and dashes allowed with a dot as delimiter. Must begin with alpha and not end with a dash or dot. No spaces.
Matches
abc.123 | abc-xyz | my-name.for.me
Non-Matches
123.abc | abc- | abc..
Author Rating: Not yet rated. tedcambron
Title Test Details URL w/ Port Option
Expression
^(\w{3,6}\:\/\/[\w\-]+(?:\.[\w\-]+)+(?:\:\d{2,4})*(?:\/?|(?:\/[\w\-]+)*)(?:\/?|\/\w+\.\w{2,4}(?:\?[\w]+\=[\w\-]+)?)?(?:\&[\w]+\=[\w\-]+)*)$
Description
Here's my relaxed version of an URL regex. This one accepts just about anything but a double dot but still must resemble an URL to pass. Unlike my other URL validater this one accepts a port. Doesn't accept out of place meta characters.
Matches
http://domain.com/ | ftp://foo.bar/dir | https://me.us/file.pl?arg=1
Non-Matches
http://domain | ftp://foo.bar//dir | https://me.us/file..pl
Author Rating: The rating for this expression. tedcambron
Title Test Details Date Matching Regex
Expression
^\d?\d([./-])\d?\d\1(?:\d\d|\d{4})$
Description
Here's a super simple one for checking dates written numerically, MM/DD/YYYY. Separators can be "/", "-", or "." and must be the same. Because of it's simplicity it will allow dates that don't exist but that doesn't matter if you're looking for a basic date format checker and like to keep it simple.
Matches
1/2/14 | 01-02-2014 | 1.20.14
Non-Matches
1/2/014 | 1-2.2014 | Jan.2, 2014
Author Rating: Not yet rated. tedcambron
Title Test Details Another Date Matching Regex
Expression
^([a-yA-Y]{3,4}(?:\.?|[a-yA-Y]{1,6}?)\s?\d?\d(?:[d-tD-T]{2})?\,?\s?(?:\'?\d\d|\d{4}))$
Description
This will match things resembling a written date. It will match dates written incorrectly of course but this cute and funny date matching regex is for the beauty of the simplicity in checking the many ways to write a date.
Matches
Jan. 1, 2014 | January 1, '14 | JAN 1ST 2014
Non-Matches
this is not a date | 123 isn't either | neither is this!
Author Rating: Not yet rated. tedcambron
Change page:   |    Displaying page 1 of 2 pages; Items 1 to 20

Copyright © 2001-2024, RegexAdvice.com | ASP.NET Tutorials