---
title: "Mera regexp och länkar"
type: "forum-thread"
url: "https://www.webforum.nu/amne/asp/153409-mera-regexp-och-länkar"
topic: "ASP"
topic_url: "https://www.webforum.nu/amne/asp"
author: "peppar"
published: "2006-11-05T19:06:28.000Z"
updated: "2006-11-06T10:29:10.000Z"
replies: 1
views: 337
page: 1
pages: 1
language: "sv-SE"
site: "webForum — webforum.nu"
rights: "Upphovsrätten till varje inlägg tillhör dess författare."
attribution: "Citera som: webForum, https://www.webforum.nu/amne/asp/153409-mera-regexp-och-länkar"
---

# Mera regexp och länkar

## #1 — peppar, 2006-11-05T19:06Z

Har denna funktion som jag hittat här på WF 

```
Function convertLink(ByVal strText)
Dim mDelimit
Dim re
mDelimit = Chr(0)
Set re = New RegExp
re.Global = True
re.IgnoreCase = true

re.Pattern = "(\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+)"
strText = re.Replace(strText, "<a href=""mailto" & mDelimit & ":$1"">$1</a>")

re.Pattern = "(http://|https://|ftp://|mailto:)(\S)(\S+)"
strText = re.Replace(strText, "<a href=""$1$2" & mDelimit & "$3"" target=""_blank"">$2" & mDelimit & "$3</a>")

re.Pattern = "(www\.(\S)(\S+))"
strText = re.Replace(strText, "<a href=""http://$1"" target=""_blank"">$1</a>")
strText = Replace(strText, mDelimit, "")

convertLink=strText

End Function
```

 
om jag skickar in en adress innesluten i \[ url = http: / / ww w.adress . se\]nätadress \[/ url \] (ursäkta mellanslagen men WF parsar annars strängnen som länk ;)
Så vill jag ju ha ordet "nätadress" länkat till adressen som anges i "url=" ... men jag får ut en sträng som ser en aning konstig ut... jag bifogar en screenshot.

Jag får inte ihop det... vad gör jag för fel?

Bilagor:

- [wfscreen.jpg](https://www.webforum.nu/a/12802.jpg)

Permalänk: https://www.webforum.nu/p/153409

## #2 — Peter S, 2006-11-06T10:29Z

```
Function convertLink(ByVal strText)
Dim mDelimit
Dim re
mDelimit = Chr(0)
Set re = New RegExp
re.Global = True
re.IgnoreCase = true

re.pattern = "\&#91;url=([^]]+)](.+?)\[/url]"
strText = re.replace(strText, "<a href=""$1"">$2</a>")

re.Pattern = "(\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+)"
strText = re.Replace(strText, "<a href=""mailto" & mDelimit & ":$1"">$1</a>")

re.Pattern = "(^|\s)(http://|https://|ftp://|mailto:)(\S)(\S+)"
strText = re.Replace(strText, "$1<a href=""$2$3" & mDelimit & "$4"" target=""_blank"">$3" & mDelimit & "$4</a>")

re.Pattern = "(^|\s)(www\.(\S)(\S+))"
strText = re.Replace(strText, "$1<a href=""http://$2"" target=""_blank"">$2</a>")
strText = Replace(strText, mDelimit, "")

convertLink=strText

End Function
```

Permalänk: https://www.webforum.nu/p/1893307

---

Tråden på webben: https://www.webforum.nu/amne/asp/153409-mera-regexp-och-länkar
