导航
  • 主页
  • .NET Framework
  • ASP
  • Web Services
  • .NET互联网桌面应用
  • VB
  • 图表区
  • 分析与设计
  • 组件/控件开发
  • AppLauncher
  • 问答

求把ubb代码转换成html的正则表达式代码

mongmong 2004-07-12 03:55:35
不胜感激
...全文
168 点赞 收藏 11
写回复
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
zipo 2005-03-01
buyifly(冬雷物语
写的对不对啊?
帮你顶下吧!
回复
warren1999 2005-03-01
up
回复
chengbo1983 2005-01-19
收藏
回复
liulxmooo 2005-01-19
up
回复
junstyle 2005-01-19
Mark~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
回复
leo_boy 2005-01-19
<SCRIPT RUNAT="SERVER">
function ubb(vstr as string)

'替换HTML标记及换行处理
vstr = replace(vstr, ">", ">")
vstr = replace(vstr, "<", "<")
vstr = Replace(vstr, CHR(32), " ")
vstr = Replace(vstr, CHR(9), "  ")
vstr = Replace(vstr, CHR(34), """)
vstr = Replace(vstr, CHR(39), "'")
vstr = Replace(vstr, CHR(13), "")
vstr = Replace(vstr, CHR(10), "<BR> ")
vstr = Replace(vstr, "[enter]", "<BR> ")

dim xface as integer
if xface=1 then
'表情转换,数值型变量xface=1时,允许转换
vstr = replace(vstr,":)","<img src=""em/em1.gif"">")
vstr = replace(vstr,":(","<img src=""em/em2.gif"">")
vstr = replace(vstr,":o","<img src=""em/em3.gif"">")
vstr = replace(vstr,":D","<img src=""em/em4.gif"">")
vstr = replace(vstr,";)","<img src=""em/em5.gif"">")
vstr = replace(vstr,":p","<img src=""em/em6.gif"">")
vstr = replace(vstr,":cool:","<img src=""em/em7.gif"">")
vstr = replace(vstr,":mad:","<img src=""em/em8.gif"">")
vstr = replace(vstr,":eek:","<img src=""em/em9.gif"">")
vstr = replace(vstr,":?:","<img src=""em/em0.gif"">")
end if

dim objregex as RegEx

'屏蔽JS等等
objregex = new regex("javascript")
vstr = objregex.replace(vstr,"&#106avascript")
objregex = new regex("jscript:")
vstr = objregex.replace(vstr,"&#106script:")
objregex = new regex("js:")
vstr = objregex.replace(vstr,"&#106s:")
objregex = new regex("value")
vstr = objregex.replace(vstr,"&#118alue")
objregex = new regex("about:")
vstr = objregex.replace(vstr,"about:")
objregex = new regex("file:")
vstr = objregex.replace(vstr,"file:")
objregex = new regex("document.cookie")
vstr = objregex.replace(vstr,"documents&#46cookie")
objregex = new regex("vbscript:")
vstr = objregex.replace(vstr,"&#118bscript:")
objregex = new regex("vbs:")
vstr = objregex.replace(vstr,"&#118bs:")
objregex = new regex("(on(mouse|exit|error|click|key))")
vstr = objregex.replace(vstr,"&#111n$2")
objregex = new regex("script")
vstr = objregex.replace(vstr,"&#115cript")

'UBB转换
'url
objregex = new regex("\[url\](http|https|ftp):\/\/(.[^\[]*)\[\/url\]")
vstr = objregex.replace(vstr,"<a href=""$1://$2"" TARGET=""_blank"">$1://$2</a>")
'EMAIL
objregex = new regex("\[email\](.[^\[]*)\[\/email\]")
vstr = objregex.replace(vstr,"<a href=""mailto:$1"" TARGET=""_blank"">$1</a>")
'IMG
objregex = new regex("\[img\](http|https|ftp):\/\/(.[^\[]*)\[\/img\]")
vstr = objregex.replace(vstr,"<br><a onfocus=this.blur() href=""$1://$2"" target=_blank><IMG SRC=""$1://$2"" border=0 alt=按此在新窗口浏览图片 onload=""javascript:if(this.width>screen.width-333)this.width=screen.width-333""></a>")
'自动识别URL
objregex = new regex("\[url=(http:\/\/.[^\[]*)\](.[^\[]*)(\[\/url\])")
vstr = objregex.replace(vstr,"<a href=""$1"" target=""_blank"">$2</a>")
objregex = new regex("^(http://[A-Za-z0-9\./=\?%\-&_~`@':+!]+)")
vstr = objregex.replace(vstr,"<a href=""$1"" target=""_blank"">$1</a>")
objregex = new regex("(http://[A-Za-z0-9\./=\?%\-&_~`@':+!]+)$")
vstr = objregex.replace(vstr,"<a target=_blank href=$1>$1</a>")
objregex = new regex("[^>=""](http://[A-Za-z0-9\./=\?%\-&_~`@':+!]+)")
vstr = objregex.replace(vstr,"<a target=_blank href=$1>$1</a>")
'COLOR
objregex = new regex("\[color=(.[^\[]*)\](.[^\[]*)\[\/color\]")
vstr = objregex.replace(vstr,"<font color=""$1"">$2</font>")
'u
objregex = new regex("\[u\](.*)\[\/u\]")
vstr = objregex.replace(vstr,"<u>$1</u>")
'B
objregex = new regex("\[b\](.*)\[\/b\]")
vstr = objregex.replace(vstr,"<b>$1</b>")
'I
objregex = new regex("\[i\](.*)\[\/i\]")
vstr = objregex.replace(vstr,"<i>$1</i>")
'FLY
objregex = new regex("\[fly\](.*)\[\/fly\]")
vstr = objregex.replace(vstr,"<marquee width=""80%"" behavior=""alternate"" scrollamount=""3"">$1</marquee>")
'SHADOW
objregex = new regex("\[shadow=*(#*[a-z0-9]*),*([0-9]*)\](.[^\[]*)\[\/shadow\]")
vstr = objregex.replace(vstr,"<span style=""filter: Shadow(Color=$1, Direction=$2)"">$3</span>")
'CODE
objregex = new regex("\[code\](.*)\[\/code\]")
vstr = objregex.replace(vstr,"<table width=""80%"" border=""0"" cellpadding=""2"" cellspacing=""0"" bgcolor=""#99FFCC"" style=""border:1px solid #000000;font-size:9pt;font-family:tahoma""><tr><td>$1</td></tr></table>")
'完成,还可以自己扩展
ubb = vstr
end function
</SCRIPT>
回复
lin_lin 2005-01-19
收藏
回复
nga96 2005-01-19
收藏,好东西
回复
fangyifeng 2005-01-19
public string Texttohtml(string chr)
{

if(chr==null)
return "";
chr=chr.Replace("<","<");
chr=chr.Replace(">",">");
chr=chr.Replace("\n","<br/>");
chr = Regex.Replace(chr,@"\[url=(?<x>[^\]]*)\](?<y>[^\]]*)\[/url\]",@"<a href=$1 target=_blank class=maintext>$2</a>",RegexOptions.IgnoreCase);
chr = Regex.Replace(chr,@"\[url\](?<x>[^\]]*)\[/url\]",@"<a href=$1 target=_blank class=maintext>$1</a>",RegexOptions.IgnoreCase);
chr = Regex.Replace(chr,@"\]*)\](?<y>[^\]]*)\[/email\]",@"<a href=$1>$2</a>",RegexOptions.IgnoreCase);
chr = Regex.Replace(chr,@"\[email\](?<x>[^\]]*)\[/email\]",@"<a href=$1>$1</a>",RegexOptions.IgnoreCase);
//chr = Regex.Replace(chr,@"\[flash](?<x>[^\]]*)\[/flash]",@"<OBJECT codeBase=http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=4,0,2,0 classid=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000 width=500 height=400><PARAM NAME=movie VALUE=""$1""><PARAM NAME=quality VALUE=high><embed src=""$1"" quality=high pluginspage='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash' type='application/x-shockwave-flash' width=500 height=400>$1</embed></OBJECT>",RegexOptions.IgnoreCase);
chr = Regex.Replace(chr,@"\[img](?<x>[^\]]*)\[/img]",@"<IMG SRC=""$1"" border=0>",RegexOptions.IgnoreCase);
//chr = Regex.Replace(chr,@"\[color=(?<x>[^\]]*)\](?<y>[^\]]*)\[/color\]",@"<font color=$1>$2</font>",RegexOptions.IgnoreCase);
//chr = Regex.Replace(chr,@"\[face=(?<x>[^\]]*)\](?<y>[^\]]*)\[/face\]",@"<font face=$1>$2</font>",RegexOptions.IgnoreCase);
//chr = Regex.Replace(chr,@"\[size=1\](?<x>[^\]]*)\[/size\]",@"<font size=1>$1</font>",RegexOptions.IgnoreCase);
//chr = Regex.Replace(chr,@"\[size=2\](?<x>[^\]]*)\[/size\]",@"<font size=2>$1</font>",RegexOptions.IgnoreCase);
//chr = Regex.Replace(chr,@"\[size=3\](?<x>[^\]]*)\[/size\]",@"<font size=3>$1</font>",RegexOptions.IgnoreCase);
//chr = Regex.Replace(chr,@"\[size=4\](?<x>[^\]]*)\[/size\]",@"<font size=4>$1</font>",RegexOptions.IgnoreCase);
//chr = Regex.Replace(chr,@"\[align=(?<x>[^\]]*)\](?<y>[^\]]*)\[/align\]",@"<align=$1>$2</align>",RegexOptions.IgnoreCase);
//chr = Regex.Replace(chr,@"\[fly](?<x>[^\]]*)\[/fly]",@"<marquee width=90% behavior=alternate scrollamount=3>$1</marquee>",RegexOptions.IgnoreCase);
//chr = Regex.Replace(chr,@"\[move](?<x>[^\]]*)\[/move]",@"<marquee scrollamount=3>$1</marquee>",RegexOptions.IgnoreCase);
//chr = Regex.Replace(chr,@"\[glow=(?<x>[^\]]*),(?<y>[^\]]*),(?<z>[^\]]*)\](?<w>[^\]]*)\[/glow\]",@"<table width=$1 style='filter:glow(color=$2, strength=$3)'>$4</table>",RegexOptions.IgnoreCase);
//chr = Regex.Replace(chr,@"\[shadow=(?<x>[^\]]*),(?<y>[^\]]*),(?<z>[^\]]*)\](?<w>[^\]]*)\[/shadow\]",@"<table width=$1 style='filter:shadow(color=$2, strength=$3)'>$4</table>",RegexOptions.IgnoreCase);
chr = Regex.Replace(chr,@"\[b\](?<x>[^\]]*)\[/b\]",@"<b>$1</b>",RegexOptions.IgnoreCase);
chr = Regex.Replace(chr,@"\[i\](?<x>[^\]]*)\[/i\]",@"<i>$1</i>",RegexOptions.IgnoreCase);
chr = Regex.Replace(chr,@"\[u\](?<x>[^\]]*)\[/u\]",@"<u>$1</u>",RegexOptions.IgnoreCase);
//chr = Regex.Replace(chr,@"\[code\](?<x>[^\]]*)\[/code\]",@"<pre id=code><font size=1 face='Verdana, Arial' id=code>$1</font id=code></pre id=code>",RegexOptions.IgnoreCase);
//chr = Regex.Replace(chr,@"\[list\](?<x>[^\]]*)\[/list\]",@"<ul>$1</ul>",RegexOptions.IgnoreCase);
//chr = Regex.Replace(chr,@"\[list=1\](?<x>[^\]]*)\[/list\]",@"<ol type=1>$1</ol id=1>",RegexOptions.IgnoreCase);
//chr = Regex.Replace(chr,@"\[list=a\](?<x>[^\]]*)\[/list\]",@"<ol type=a>$1</ol id=a>",RegexOptions.IgnoreCase);
//chr = Regex.Replace(chr,@"\[\*\](?<x>[^\]]*)\[/\*\]",@"<li>$1</li>",RegexOptions.IgnoreCase);
return(chr);
}
回复
listhome 2004-12-06
收藏
回复
buyifly 2004-12-06
public static string FormatDetail(string sDetail)
{
Regex r;
Match m;

//处理空格
sDetail = sDetail.Replace(" "," ");
sDetail = sDetail.Replace("<","<");
sDetail = sDetail.Replace(">",">");
//sDetail = sDetail.Replace("\r\n","<BR><BR>");
//sDetail = sDetail.Replace("\n","<BR>");
//处标记
r = new Regex(@"(\[b\])([ \S\t]*?)(\[\/b\])",RegexOptions.IgnoreCase);
for (m = r.Match(sDetail); m.Success; m = m.NextMatch())
{
sDetail = sDetail.Replace(m.Groups[0].ToString(),"<B>" + m.Groups[2].ToString() + "</B>");
}
//处标记
r = new Regex(@"(\[i\])([ \S\t]*?)(\[\/i\])",RegexOptions.IgnoreCase);
for (m = r.Match(sDetail); m.Success; m = m.NextMatch())
{
sDetail = sDetail.Replace(m.Groups[0].ToString(),"<I>" + m.Groups[2].ToString() + "</I>");
}
//处标记
r = new Regex(@"(\[U\])([ \S\t]*?)(\[\/U\])",RegexOptions.IgnoreCase);
for (m = r.Match(sDetail); m.Success; m = m.NextMatch())
{
sDetail = sDetail.Replace(m.Groups[0].ToString(),"<U>" + m.Groups[2].ToString() + "</U>");
}
//处[p][/p]标记
r = new Regex(@"((\r\n)*\[p\])(.*?)((\r\n)*\[\/p\])",RegexOptions.IgnoreCase|RegexOptions.Singleline);
for (m = r.Match(sDetail); m.Success; m = m.NextMatch())
{
sDetail = sDetail.Replace(m.Groups[0].ToString(),"<P class=\"pstyle\">" + m.Groups[3].ToString() + "</P>");
}
//处[sup][/sup]标记
r = new Regex(@"(\[sup\])([ \S\t]*?)(\[\/sup\])",RegexOptions.IgnoreCase);
for (m = r.Match(sDetail); m.Success; m = m.NextMatch())
{
sDetail = sDetail.Replace(m.Groups[0].ToString(),"<SUP>" + m.Groups[2].ToString() + "</SUP>");
}
//处[sub][/sub]标记
r = new Regex(@"(\[sub\])([ \S\t]*?)(\[\/sub\])",RegexOptions.IgnoreCase);
for (m = r.Match(sDetail); m.Success; m = m.NextMatch())
{
sDetail = sDetail.Replace(m.Groups[0].ToString(),"<SUB>" + m.Groups[2].ToString() + "</SUB>");
}
//处标记
r = new Regex(@"(\[url\])([ \S\t]*?)(\[\/url\])",RegexOptions.IgnoreCase);
for (m = r.Match(sDetail); m.Success; m = m.NextMatch())
{
sDetail = sDetail.Replace(m.Groups[0].ToString(),
"<A href=\"" + m.Groups[2].ToString() + "\" target=\"_blank\"><IMG border=0 src=\"images/url.gif\">" +
m.Groups[2].ToString() + "</A>");
}
//处xxx标记
r = new Regex(@"(\[url=([ \S\t]+)\])([ \S\t]*?)(\[\/url\])",RegexOptions.IgnoreCase);
for (m = r.Match(sDetail); m.Success; m = m.NextMatch())
{
sDetail = sDetail.Replace(m.Groups[0].ToString(),
"<A href=\"" + m.Groups[2].ToString() + "\" target=\"_blank\"><IMG border=0 src=\"images/url.gif\">" +
m.Groups[3].ToString() + "</A>");
}
//处标记
r = new Regex(@"(\ for (m = r.Match(sDetail); m.Success; m = m.NextMatch())
{
sDetail = sDetail.Replace(m.Groups[0].ToString(),
"<A href=\"mailto:" + m.Groups[2].ToString() + "\" target=\"_blank\"><IMG border=0 src=\"images/email.gif\">" +
m.Groups[2].ToString() + "</A>");
}
//处">)([ \S\t]*?)(\[\/email\])",RegexOptions.IgnoreCase);
for (m = r.Match(sDetail); m.Success; m = m.NextMatch())
{
sDetail = sDetail.Replace(m.Groups[0].ToString(),
"<A href=\"mailto:" + m.Groups[2].ToString() + "\" target=\"_blank\"><IMG border=0 src=\"images/email.gif\">" +
m.Groups[2].ToString() + "</A>");
}
//处[email=xxx]标记
r = new Regex(@"(\[email=([ \S\t]+)\])([ \S\t]*?)(\[\/email\])",RegexOptions.IgnoreCase);
for (m = r.Match(sDetail); m.Success; m = m.NextMatch())
{
sDetail = sDetail.Replace(m.Groups[0].ToString(),
"<A href=\"mailto:" + m.Groups[2].ToString() + "\" target=\"_blank\"><IMG border=0 src=\"images/email.gif\">" +
m.Groups[3].ToString() + "</A>");
}
//处[size=x][/size]标记
r = new Regex(@"(\[size=([1-7])\])([ \S\t]*?)(\[\/size\])",RegexOptions.IgnoreCase);
for (m = r.Match(sDetail); m.Success; m = m.NextMatch())
{
sDetail = sDetail.Replace(m.Groups[0].ToString(),
"<FONT SIZE=" + m.Groups[2].ToString() + ">" +
m.Groups[3].ToString() + "</FONT>");
}
//处标记
r = new Regex(@"(\[color=([\S]+)\])([ \S\t]*?)(\[\/color\])",RegexOptions.IgnoreCase);
for (m = r.Match(sDetail); m.Success; m = m.NextMatch())
{
sDetail = sDetail.Replace(m.Groups[0].ToString(),
"<FONT COLOR=" + m.Groups[2].ToString() + ">" +
m.Groups[3].ToString() + "</FONT>");
}
//处[font=x][/font]标记
r = new Regex(@"(\[font=([\S]+)\])([ \S\t]*?)(\[\/font\])",RegexOptions.IgnoreCase);
for (m = r.Match(sDetail); m.Success; m = m.NextMatch())
{
sDetail = sDetail.Replace(m.Groups[0].ToString(),
"<FONT FACE=" + m.Groups[2].ToString() + ">" +
m.Groups[3].ToString() + "</FONT>");
}
//处理图片链接
r = new Regex("\\[picture\\](\\d+?)\\[\\/picture\\]",RegexOptions.IgnoreCase);
for (m = r.Match(sDetail); m.Success; m = m.NextMatch())
{
sDetail = sDetail.Replace(m.Groups[0].ToString(),
"<A href=\"ShowImage.aspx?Type=ALL&Action=forumImage&ImageID=" + m.Groups[1].ToString() +
"\" target=\"_blank\"><IMG border=0 Title=\"点击打开新窗口查看\" src=\"ShowImage.aspx?Action=forumImage&ImageID=" + m.Groups[1].ToString() +
"\"></A>");
}
//处理[align=x][/align]
r = new Regex(@"(\[align=([\S]+)\])([ \S\t]*?)(\[\/align\])",RegexOptions.IgnoreCase);
for (m = r.Match(sDetail); m.Success; m = m.NextMatch())
{
sDetail = sDetail.Replace(m.Groups[0].ToString(),
"<P align=" + m.Groups[2].ToString() + ">" +
m.Groups[3].ToString() + "</P>");
}
//处[H=x][/H]标记
r = new Regex(@"(\[H=([1-6])\])([ \S\t]*?)(\[\/H\])",RegexOptions.IgnoreCase);
for (m = r.Match(sDetail); m.Success; m = m.NextMatch())
{
sDetail = sDetail.Replace(m.Groups[0].ToString(),
"<H" + m.Groups[2].ToString() + ">" +
m.Groups[3].ToString() + "</H" + m.Groups[2].ToString() + ">");
}

//处理[list=x][*][/list]
r = new Regex(@"(\[list(=(A|a|I|i| ))?\]([ \S\t]*)\r\n)((\[\*\]([ \S\t]*\r\n))*?)(\[\/list\])",RegexOptions.IgnoreCase);
回复
发动态
发帖子
.NET技术社区
创建于2007-09-28

5.8w+

社区成员

.NET技术交流专区
申请成为版主
社区公告
暂无公告