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

Please support RegExLib Sponsors

Sponsors

Regular Expression Details

Title Test Find Pattern Title
Expression
(mailto\:|(news|(ht|f)tp(s?))\://)(([^[:space:]]+)|([^[:space:]]+)( #([^#]+)#)?)
Description
this is a very little regex for use within a content management software. links within textfields has not to be written in html. the editor of the cms is instructed to use it like this: 1. mention spaces in front and behind the url 2. start url with http://, mailto://, ftp:// ... 3. use optional linktext within #linktext# (separated with single space) 4. if there is no linktext the url/email will show up as linktext 5. avoid url with spaces in filename (use %20 urldecode) replace pattern (space in front): <a href="\\1\\3\\4" target="_blank">\\3\\6</a>
Matches
http://www.domain.com | http://www.domain.com/index%20page.htm #linktext# | mailto://user@domai
Non-Matches
<a href="http://www.domain.com">real html link</a> | http://www.without_space_
Author Rating: Not yet rated. Martin Schwedes
Source
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: trailing spaces
Name: Martin Schwedes
Date: 3/26/2004 4:27:14 AM
Comment:
great, thanx matt. i didn't checked new numbers after adding the more detailed syntax (mailto\:|(news|(ht|f)tp(s?))\://) ---- trailing spaces are needed to avoid regex on real html-syntax links in source-text. try this one instead of spaces in front and behind: [^"'=>] (means: not char " or char ' or char = or char >)


Title: Replace pattern
Name: Matt Grimm
Date: 3/25/2004 2:10:41 PM
Comment:
Actually, the href needs both the 6th and 7th match to work in both cases: " <a href=\"\\1\\6\\7\" title=\"\\9\" target=\"_blank\">\\6\\9</a>" It doesn't seem like the trailing space is needed in either the expression or the replace pattern.


Title: Replace pattern
Name: Matt Grimm
Date: 3/25/2004 1:56:41 PM
Comment:
I believe you will want the replace pattern to be like so (using PHP's ereg_replace fcn): " <a href=\"\\1\\7\" target=\"_blank\">\\6\\9</a> " with a leading and trailing space, and different variable numbers. This is the only way I could get the expression to work. Otherwise, very useful.


Title: Non-match doesn't work... ADD SPACES
Name: Martin Schwedes
Date: 1/16/2004 2:07:41 PM
Comment:
please note: test-form (link above) did trim all spaces ! add spaces in your code or test-form. | (mailto\:|(news|(ht|f)tp(s?))\://)(([^[:space:]]+)|([^[:space:]]+)( #([^#]+)#)?) |


Title: Non-match doesn't work...
Name: Brian Bisaillon
Date: 1/16/2004 11:53:56 AM
Comment:
I tried one of your sample non-matches in the Test box and the result was a match... <a href="http://www.domain.com">real html link</a> Therefore, it doesn't work exactly like what you said.


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