---
title: "HTML med RegExp"
type: "forum-thread"
url: "https://www.webforum.nu/amne/asp/160993-html-med-regexp"
topic: "ASP"
topic_url: "https://www.webforum.nu/amne/asp"
author: "SGuncel"
published: "2007-06-01T07:35:36.000Z"
updated: "2007-06-01T10:52:08.000Z"
replies: 3
views: 367
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/160993-html-med-regexp"
---

# HTML med RegExp

## #1 — SGuncel, 2007-06-01T07:35Z

Jag använder mina egna HTML koder med RegExp som nästan alla gör för att skydda sig från andra HTML koder.
Men problmet för mig är att jag kan bara använda några koder en gång eller så när jag använder \<b\>\</b\> blir alla text fett.

```
<%
     Function ForumHTML(ByVal strText)

     strText = Replace(Server.HTMLEncode(strText),vbCrlf,"<br>")
     Set objRegExp = New regexp
     objRegExp.Global = true
     objRegExp.IgnoreCase = true

        objRegExp.Pattern = "(http://(\w|\.|/|-|\?|=|&|;|~){1,}\w*)"
        strText = objRegExp.replace(strtext,"<a href=""$1"" target=""_blank"">$1</a>")
		
        objRegExp.Pattern="\&lt;img src=&quot;([\w\W]*?)&quot;&gt;"
        strText = objRegExp.replace(strText,"<img src=""$1"">")
		
        objRegExp.pattern="\&lt;font color=&quot;([^&]*)&quot;\&gt;([^\[]*)\&lt;/font\&gt;"
        strText = objRegExp.Replace(strtext,"<font color=""$1"">$2</font>")
        
        objRegExp.pattern="\&lt;font size=&quot;([\w\W]*?)&quot;\&gt;([^\[]*)\&lt;/font\&gt;"
        strText = objRegExp.Replace(strtext,"<font size=""$1"">$2</font>")
        
        objRegExp.pattern="\&lt;font face=&quot;([\w\W]*?)&quot;\&gt;([^\[]*)\&lt;/font\&gt;"
        strText = objRegExp.Replace(strtext,"<font face=""$1"">$2</font>")
        
        objRegExp.pattern="\&lt;ul&gt; &lt;li&gt;([^\[]*)\&lt;/li&gt; &lt;/ul&gt;"
        strText = objRegExp.Replace(strtext,"<ul> <li>$1</ul> </li>")

		strText = Replace(strText,":)","<img src=""../_Grafik/Smilies/smile.gif"">")
		strText = Replace(strText,":(","<img src=""../_Grafik/Smilies/sur.gif"">")
		strText = Replace(strText,";)","<img src=""../_Grafik/Smilies/blink.gif"">")
		strText = Replace(strText,":'(","<img src=""../_Grafik/Smilies/cry.gif"">")
		strText = Replace(strText,":$","<img src=""../_Grafik/Smilies/blush.gif"">")
		
		strText = Replace(strText,":D","<img src=""../_Grafik/Smilies/garv.gif"">")
		strText = Replace(strText,":d","<img src=""../_Grafik/Smilies/garv.gif"">")
		
		strText = Replace(strText,":@","<img src=""../_Grafik/Smilies/angry.gif"">")
		
		strText = Replace(strText,":o","<img src=""../_Grafik/Smilies/happen.gif"">")
		strText = Replace(strText,":O","<img src=""../_Grafik/Smilies/happen.gif"">")

		strText = Replace(strText,"(L)","<img src=""../_Grafik/Smilies/heart.gif"">")		
		strText = Replace(strText,"halay","<img src=""../_Grafik/Smilies/halay.gif"">")
		strText = Replace(strText,"Halay","<img src=""../_Grafik/Smilies/halay.gif"">")
		strText = Replace(strText,"peace","<img src=""../_Grafik/Smilies/peace.gif"">")
		strText = Replace(strText,"Peace","<img src=""../_Grafik/Smilies/peace.gif"">")
	
        
        strText = Replace(strText,"&lt;b&gt;", "<b>")
        strText = Replace(strText,"&lt;/b&gt;", "</b>")
        strText = Replace(strText,"&lt;i&gt;", "<i>")
        strText = Replace(strText,"&lt;/i&gt;", "</i>")
        strText = Replace(strText,"&lt;u&gt;", "<u>")
        strText = Replace(strText,"&lt;/i&gt;", "</u>") 		
        strText = Replace(strText,"&lt;center&gt;","<div align='center'>")
        strText = Replace(strText,"&lt;/center&gt;","</div>")
        strText = Replace(strText,"&lt;right&gt;","<div align=""right"">")
        strText = Replace(strText,"&lt;/right&gt;","</div>")

     ForumHTML = strText
     End function
%>
```

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

## #2 — voigtann1, 2007-06-01T09:31Z

är väl problem med stora och småbokstäver?

Vet inte om det hjälper men "kortade" ner lite i slutet ta bort:

```
        
        strText = Replace(strText,"&lt;b&gt;", "<b>")
        strText = Replace(strText,"&lt;/b&gt;", "</b>")
        strText = Replace(strText,"&lt;i&gt;", "<i>")
        strText = Replace(strText,"&lt;/i&gt;", "</i>")
        strText = Replace(strText,"&lt;u&gt;", "<u>")
        strText = Replace(strText,"&lt;/i&gt;", "</u>")
```

och ersätt med:

```
        objRegExp.pattern="&lt;(\/?[biu])&gt;"
        strText = objRegExp.Replace(strtext,"<$1>")
```

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

## #3 — SGuncel, 2007-06-01T09:54Z

Fel, med båda stora och småbokstäver.

Men koden som gav löste det.

Men jag kan fortfarande inte använde \<font size=""\>\</font\>, \<ul\> \<li\>\</ul\> \</li\> och andra koder flera gånger.

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

## #4 — voigtann1, 2007-06-01T10:52Z

lägg till \\ på alla / ?

en sak:
\<ul\> \<li\>$1\</ul\> \</li\> är ju fel skrivit.. ska vara \<ul\>\<li\>$1\</li\>\</ul\>

du skulle mycket väl kunna använda det i "mitt" pattern med..:

```
        objRegExp.pattern="&lt;(\/?([biu]|ul|li))&gt;"
        strText = objRegExp.Replace(strtext,"<$1>")
```

osv..

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

---

Tråden på webben: https://www.webforum.nu/amne/asp/160993-html-med-regexp
