- The first Regular Expression Library on the Web!

Please support RegExLib Sponsors


Regular Expression Details

Title Test Find Pattern Title
(mailto\:|(news|(ht|f)tp(s?))\://)(([^[:space:]]+)|([^[:space:]]+)( #([^#]+)#)?)
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 | #linktext# | mailto://user@domai
<a href="">real html link</a> | http://www.without_space_
Author Rating: Not yet rated. Martin Schwedes
Your Rating
Bad Good

Enter New 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
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
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
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
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
I tried one of your sample non-matches in the Test box and the result was a match... <a href="">real html link</a> Therefore, it doesn't work exactly like what you said.

Copyright © 2001-2019, | ASP.NET Tutorials