---
title: "Ta bort querystrings regexp"
type: "forum-thread"
url: "https://www.webforum.nu/amne/asp/170241-ta-bort-querystrings-regexp"
topic: "ASP"
topic_url: "https://www.webforum.nu/amne/asp"
author: "sifix"
published: "2008-03-26T12:06:56.000Z"
updated: "2008-03-26T13:12:07.000Z"
replies: 4
views: 518
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/170241-ta-bort-querystrings-regexp"
---

# Ta bort querystrings regexp

## #1 — sifix, 2008-03-26T12:06Z

Finns det nåt sätt att ta bort querystrings så att 

```
http://www.ensida.se?id=345
```

blir

```
<a href="http://www.ensida.se?id=345">www.ensida.se</a>
```

 
när man kör denna?

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

re.pattern = "\[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/170241

## #2 — voigtann1, 2008-03-26T12:19Z

Ersätt:

```
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>")
```

med:

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

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

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

## #3 — sifix, 2008-03-26T12:44Z

Funkar med 

```
www.ensida.se?id=345
```

 men skriver man 

```
http://www.ensida.se?id=345
```

 så blir det så här

```
<a href="http://<a href="http://www.ensida.se?id=345" target="_blank">www.ensida.se</a>" target="_blank">http://<a href="http://www.ensida.se</a" target="_blank">www.ensida.se</a</a>>
```

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

## #4 — voigtann1, 2008-03-26T13:01Z

```
re.Pattern = "(^|\s)(www\.[^\s\?]+)(\?[^\s]+)?(?=$|\W)"
strText = re.Replace(strText, "$1<a href=""http://www.$2$3"" target=""_blank"">$2</a>")
```

istället för:

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

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

## #5 — sifix, 2008-03-26T13:12Z

Tackar, nu funkar det.

Så här blev det till slut.

```
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 = "\b(http://|https://|ftp://|mailto:)(\S+)(\?\S+)\b"
strText = re.Replace(strText, "<a href=""$1$2$3"" target=""_blank"">$2</a>")

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

strText = Replace(strText, mDelimit, "")

convertLink=strText

End Function
```

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

---

Tråden på webben: https://www.webforum.nu/amne/asp/170241-ta-bort-querystrings-regexp
