Does anyone have an example of a regular expression that takes all hyperlinks and email addresses and converts them into links? The text displayed would be the same text as the hyperlink or email address, but it would be a link, either an <a href> or <a mailto> link, depending on which it is. The other thing I would want is for the link text displayed be limited in length. For instance, if the string was 200 characters long, I could tell the regular expression function to limit the length to 50 characters, and add a "..." to the end of the link, hiding 150 characters and showing the first 50. Any ideas? Here is what I have now but cannot seem to figure out how to implement the character length bit:
Code:Function LinkURLs(tempTxt) Dim regEx Set regEx = New RegExp regEx.Global = True regEx.IgnoreCase = True 'Hyperlink Email Addresses regEx.Pattern = "([_.a-z0-9-]+@[_.a-z0-9-]+\.[a-z]{2,3})" tempTxt = regEx.Replace(tempTxt, "<a href=""mailto:$1"" class=""blackBold"">$1</a>") 'Hyperlink URL's regEx.Pattern = "((www\.|(http|https|ftp|news|file)+\:\/\/)[_.a-z0-9-]+\.[a-z0-9\/_:@=.+?,##%&~-]*[^.|\'|\# |!|\(|?|,| |>|<|;|\)])" tempTxt = regEx.Replace(tempTxt, "<a href=""$1"" class=""blackBold"" target=""_blank"">$1</a>") 'Make <a href="www = <a href="http://www tempTxt = Replace(tempTxt, "href=""www", "href=""http://www") LinkURLs = tempTxt & vbCrLf End Function



LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks