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

Please support RegExLib Sponsors

Sponsors

Regular Expression Details

Title Test Find URI Validation & Extraction
Expression
^((http|https|ftp):\/\/)?((.*?):(.*?)@)?([a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])((\.[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])*)(:([0-9]{1,5}))?((\/.*?)(\?(.*?))?(\#(.*))?)?$
Description
Validates and extracts URI components. Protocol is optional. Username & Password is optional. Host regex was taken from Remi Sabourin and follows RFC1035 except that it allows hostnames greater than 253 chars. Also TLD length is not restriced. Port number is optional. Absolute Path is optional, and also extracts the optional querystring and optional anchor reference.
Matches
http://john:@www.domain.com:8080/index.html?param=value#Page1
Non-Matches
http://www.domain.com:/ | www-.domain.com
Author Rating: Not yet rated. John Bayly
Source Remi Sabourin
Your Rating
Bad Good

Enter New Comment

Title
 
Name
 
Comment
 
Spammers suck - we apologize. Please enter the text shown below to enable your comment (not case sensitive - try as many times as you need to if the first ones are too hard):

Existing User Comments

Title: Mr.
Name: Putinas Piliponis
Date: 12/13/2007 6:03:36 AM
Comment:
Better version of this. in backreference goes preceselly protocol, username, password, hostname and port. As well faster since doesn't use backtracing: ^(?:(http|https|ftp):\/\/)?(?:([^:]+):([^@]+)@)?((?:[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])(?:(?:\.[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])*))(?::([0-9]{1,5}))?((\/.*?)(\?(.*?))?(\#(.*))?)?$


Title: Mr.
Name: Putinas Piliponis
Date: 12/13/2007 5:50:36 AM
Comment:
Better version of this. in backreference goes preceselly protocol, username, password, hostname and port. As well faster since doesn't use backtracing: ^(?:(http|https|ftp):\/\/)?(?:([^:]+):([^@]+)@)?((?:[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])(?:(?:\.[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])*))(?::([0-9]{1,5}))?((\/.*?)(\?(.*?))?(\#(.*))?)?$


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