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

Please support RegExLib Sponsors

Sponsors

Regular Expression Details

Title Test Find Pattern Title
Expression
\b(((\S+)?)(@|mailto\:|(news|(ht|f)tp(s?))\://)\S+)\b
Description
Whilst writing a plain-text to HTML function, I ran into the problem of links that users had written with <a> tags (as opposed to just writing the URL) were linking improperly. This regular expression returns many types of URL, and preceding characters, if any. This allows you to handle each type of match appropriately
Matches
href='http://www.deepart.org' | [email protected] | ftp://123.123.123.123
Non-Matches
www.deepart.org | deepart.org | 123.123.123.123
Author Rating: Not yet rated. Demo Gorgon
Source The concept of (ht|f)tp(s?) came from, I believe, TwoGuysFromRolla. The rest is yours truly.
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: AAA
Name: UUU
Date: 6/17/2016 11:35:09 PM
Comment:
1- sozumoki.com/tolgaozturk 2- http://google.com 3- https://google.com 4- http://www.google.com/heygidihey 5- https://www.google.com


Title: Works
Name: Vu Quang Thang
Date: 2/26/2012 3:26:17 AM
Comment:
I tried it with PHP and it works perfectly. Thank you so much.


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