社区
.NET Framework
帖子详情
求把ubb代码转换成html的正则表达式代码
mongmong
2004-07-12 03:40:17
哪位大虾给个范例出来?不胜感激
...全文
188
7
打赏
收藏
求把ubb代码转换成html的正则表达式代码
哪位大虾给个范例出来?不胜感激
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
7 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
mongmong
2004-07-14
打赏
举报
回复
谢谢了
Alexandria
2004-07-14
打赏
举报
回复
好长
Truly
2004-07-13
打赏
举报
回复
MatchCollection mc;
Regex r = new Regex(@"\[code\]([^\]]*)\[/code\]");
mc = r.Matches(chr);
// for(int i = 0; i < mc.Count; i++)
// {
// chr = chr.Replace(mc[i].ToString(),Code(mc[i].ToString()));
// }
chr = Regex.Replace(chr,@"\[code\](?<x>[^\]]*)\[/code\]",@"以下内容为程序代码:<table border='0' width='100%' style='TABLE-LAYOUT: fixed' cellpadding='10' cellspacing='1' bgcolor='#000000'><tr><td bgcolor='#FFFFFF'>$1</td></tr></table>",RegexOptions.IgnoreCase);
r = new Regex(@"\[html\]([^\]]*)\[/html\]");
mc = r.Matches(chr);
// for(int i = 0; i < mc.Count; i++)
// {
// chr = chr.Replace(mc[i].ToString(),Html(mc[i].ToString()));
// }
chr = Regex.Replace(chr,@"\[html\](?<x>[^\]]*)\[/html\]",@"以下内容为页面代码:<table border='0' width='100%' style='TABLE-LAYOUT: fixed' cellpadding='10' cellspacing='1' bgcolor='#000000'><tr><td bgcolor='#FFFFFF'><font color='#0000FF'>$1</font></td></tr></table>",RegexOptions.IgnoreCase);
return(chr);
}
Truly
2004-07-13
打赏
举报
回复
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,@"\[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);
chr = Regex.Replace(chr,@"\
引用
(?<x>.*)\
",@"以下内容为引用:<table border='0' width='90%' style='TABLE-LAYOUT: fixed' cellpadding='10' cellspacing='1' bgcolor='#000000'><tr><td bgcolor='#FFFFFF'>$1</td></tr></table>",RegexOptions.IgnoreCase);
chr = Regex.Replace(chr,@"\[gif](?<x>[^\]]*)\[/gif]",@"<IMG SRC='Pic/Gif.gif' border=0>此主题相关图片如下:<br><a href=""$1"" target=""_blank""><IMG SRC=""$1"" border=0></a><br>",RegexOptions.IgnoreCase);
chr = Regex.Replace(chr,@"\[jpg](?<x>[^\]]*)\[/jpg]",@"<IMG SRC='Pic/Jpg.gif' border=0>此主题相关图片如下:<br><a href=""$1"" target=""_blank""><IMG SRC=""$1"" border=0></a><br>",RegexOptions.IgnoreCase);
chr = Regex.Replace(chr,@"\[zip](?<x>[^\]]*)\[/zip]",@"<a href=""$1"" target=""_blank""><IMG SRC='Pic/Zip.gif' border=0>请点击此处下载</a><br>",RegexOptions.IgnoreCase);
chr = Regex.Replace(chr,@"\[rar](?<x>[^\]]*)\[/rar]",@"<a href=""$1"" target=""_blank""><IMG SRC='Pic/Rar.gif' border=0>请点击此处下载</a><br>",RegexOptions.IgnoreCase);
chr = Regex.Replace(chr,@"\[htm](?<x>[^\]]*)\[/htm]",@"<a href=""$1"" target=""_blank""><IMG SRC='Pic/Url.gif' border=0>请点击此处浏览</a><br>",RegexOptions.IgnoreCase);
chr = Regex.Replace(chr,@"\[doc](?<x>[^\]]*)\[/doc]",@"<a href=""$1"" target=""_blank""><IMG SRC='Pic/word.gif' border=0>请点击此处浏览</a><br>",RegexOptions.IgnoreCase);
chr = Regex.Replace(chr,@"\[xls](?<x>[^\]]*)\[/xls]",@"<a href=""$1"" target=""_blank""><IMG SRC='Pic/excel.gif' border=0>请点击此处浏览</a><br>",RegexOptions.IgnoreCase);
chr = Regex.Replace(chr,@"\[ppt](?<x>[^\]]*)\[/ppt]",@"<a href=""$1"" target=""_blank""><IMG SRC='Pic/powerpoint.gif' border=0>请点击此处浏览</a><br>",RegexOptions.IgnoreCase);
chr = Regex.Replace(chr,@"\[wps](?<x>[^\]]*)\[/wps]",@"<a href=""$1"" target=""_blank""><IMG SRC='Pic/wps.gif' border=0>请点击此处浏览</a><br>",RegexOptions.IgnoreCase);
chr = Regex.Replace(chr,@"\[mht](?<x>[^\]]*)\[/mht]",@"<a href=""$1"" target=""_blank""><IMG SRC='Pic/mht.gif' border=0>请点击此处浏览</a><br>",RegexOptions.IgnoreCase);
chr = Regex.Replace(chr,@"\[swf](?<x>[^\]]*)\[/swf]",@"<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><br>",RegexOptions.IgnoreCase);
chr = Regex.Replace(chr,@"\[mp3](?<x>[^\]]*)\[/mp3]",@"<OBJECT class=OBJECT id=MediaPlayer height=50 width=300 align=middle classid=CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95><PARAM NAME=ShowStatusBar VALUE=-1><PARAM NAME=Filename VALUE=""$1""><embed type=application/x-oleobject codebase=http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701 flename=mp src=""$1"" width=200 height=40></embed></OBJECT><br>",RegexOptions.IgnoreCase);
chr = Regex.Replace(chr,@"\[mpg](?<x>[^\]]*)\[/mpg]",@"<OBJECT class=OBJECT id=MediaPlayer height=300 width=300 align=middle classid=CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95><PARAM NAME=ShowStatusBar VALUE=-1><PARAM NAME=Filename VALUE=""$1""><embed type=application/x-oleobject codebase=http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701 flename=mp src=""$1"" width=200 height=40></embed></OBJECT><br>",RegexOptions.IgnoreCase);
chr = Regex.Replace(chr,@"\[ram](?<x>[^\]]*)\[/ram]",@"<embed src=""$1"" type=audio/x-pn-realaudio-plugin console=Clip1 controls=ControlPanel,StatusBar height=60 width=275 autostart=true>",RegexOptions.IgnoreCase);
Truly
2004-07-13
打赏
举报
回复
public string Ubb(string chr)
{
if(chr==null)
return "";
chr=chr.Replace(" "," ");
chr=chr.Replace("<","<");
chr=chr.Replace(">",">");
chr=chr.Replace("\n","<br>");
chr=chr.Replace("\t"," ");
chr = Regex.Replace(chr,@"\[url=(?<x>[^\]]*)\](?<y>[^\]]*)\[/url\]",@"<a href=$1 target=_blank>$2</a>",RegexOptions.IgnoreCase);
chr = Regex.Replace(chr,@"\[url\](?<x>[^\]]*)\[/url\]",@"<a href=$1 target=_blank>$1</a>",RegexOptions.IgnoreCase);
chr = Regex.Replace(chr,@"\[rm=(?<x>[^\]]*)\](?<y>[^\]]*)\[/rm\]",@"<a href=$1 target=_blank>$2</a>",RegexOptions.IgnoreCase);
chr = Regex.Replace(chr,@"\[rm\](?<x>[^\]]*)\[/rm\]",@"<a href=$1 target=_blank>$1</a>",RegexOptions.IgnoreCase);
//chr = Regex.Replace(chr,@"\[mpg=(?<x>[^\]]*)\](?<y>[^\]]*)\[/mpg\]",@"<a href=$1 target=_blank>$2</a>",RegexOptions.IgnoreCase);
//chr = Regex.Replace(chr,@"\[mpg\](?<x>[^\]]*)\[/mpg\]",@"<a href=$1 target=_blank>$1</a>",RegexOptions.IgnoreCase);
chr = Regex.Replace(chr,@"\[mov=(?<x>[^\]]*)\](?<y>[^\]]*)\[/mov\]",@"<a href=$1 target=_blank>$2</a>",RegexOptions.IgnoreCase);
chr = Regex.Replace(chr,@"\[mov\](?<x>[^\]]*)\[/mov\]",@"<a href=$1 target=_blank>$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]",@"<div align=center><br><a href=""$1"" target=""_blank""><IMG SRC=""$1"" border=0 align='middle'></a><br></div>",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);
「已注销」
2004-07-12
打赏
举报
回复
http://dev.csdn.net/develop/article/26/26837.shtm
hertcloud
2004-07-12
打赏
举报
回复
GZ
ubb
转换
html
,
UBB
代码
转换成
HTML
代码
当前位置:编程学习 > C#/ASP.NET >>
UBB
代码
转换成
HTML
代码
[img]http://www.baidu.com[/img][link=http://www.baidu.com]百度[/link][font=#FF0000]红色[/font]有这三种格式的
UBB
代码
,先在我要做三个函数分别
转换成
HTML
代码
转换后的结果如下百度红色请问该怎么写这三个函数?-----...
【
UBB
】
UBB
代码
简介
http://baike.baidu.com/link?url=JEDKx14OqvdvpNZjsK4As4er1ey-f-D9BDJ0jncLop0pwS8aCH-bdOfWT7u9N1mBGU9cVC4Aag6JRutzqX6kE1sdHkVq-enHJQDITy9o_E_
UBB
转
HTML
C#
代码
using System;using System.Data;using System.Configuration;using System.Collections;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.WebControls;using System.Web
将
UBB
代码
转换成
html
代码
转
ubb
代码
转化
html
代码
public static string
Ubb
Decode(string str) { str =
Html
Encode(str); str = Regex.Replace(str, @"/[url](?<url>.+?)/[/url]", "<a href='${url}' target=_blank>${url}<...
ubb
代码
转化
html
代码
ubb
代码
转化
html
代码
ubb
代码
转化
html
代码
public static string
Ubb
Decode(string str){str =
Html
Encode(str);str = Regex.Replace(str, @"/[url](?.+?)/[/url]", "${url}", RegexOptions.Compiled | RegexOptions.Igno
.NET Framework
17,748
社区成员
24,324
社区内容
发帖
与我相关
我的任务
.NET Framework
.NET技术 .NET Framework
复制链接
扫一扫
分享
社区描述
.NET技术 .NET Framework
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章