一个不错的用JavaScript实现的UBB编码函数

function JsUBB(str)  
{  
var re=//[i/](.[^/[]*)/[//i/]/gi;  
str=str.replace(re,"$1"); //斜体字  
re=//[b/](.[^/[]*)/[//b/]/gi;  
str=str.replace(re,"$1"); //粗体字  
re=//[u/](.[^/[]*)/[//u/]/gi;  
str=str.replace(re,"$1"); //下划线  
re=//[color=(.[^/[]*)/](.[^/[]*)/[//color/]/gi;  
str=str.replace(re,"$2"); //字体颜色  
re=//[size=([1-7])/](.[^/[]*)/[//size/]/gi;  
str=str.replace(re,"$2"); //字体大小  
re=//[face=(.[^/[]*)/](.[^/[]*)/[//face/]/gi;  
str=str.replace(re,"$2"); //字体  

re=//[center/](.[^/[]*)/[//center/]/gi;  
str=str.replace(re,"$1

"); //居中  
re=//[right/](.[^/[]*)/[//right/]/gi;  
str=str.replace(re,"$1
"); //右对齐  
re=//[quote/](.[^/[]*)/[//quote/]/gi; //引用  
str=str.replace(re,"$1");  

re=//[fly/](.*)/[//fly/]/gi; //飞行  
str=str.replace(re,"$1");  
re=//[move/](.*)/[//move/]/gi; //移动  
str=str.replace(re,"$1");  
re=//[SHADOW=*([0-9]*),*(#*[a-z0-9]*),*([0-9]*)/](.[^/[]*)/[//SHADOW]/gi; //阴影  
str=str.replace(re,"$4");  
re=//[GLOW=*([0-9]*),*(#*[a-z0-9]*),*([0-9]*)/](.[^/[]*)/[//GLOW]/gi; //外发光  
str=str.replace(re,"$4")  

re=//[URL/](.[^/[]*)/[//URL/]/gi;  
str=str.replace(re,"$1"); //超链接1  
re=//[URL=(.[^/[]*)/](.[^/[]*)/[//URL/]/gi;  
str=str.replace(re,"$2"); //超链接2  

re=//[EMAIL/]([/w-]+(/.[/w-]+)*@[/w-]+(/.[/w-]+)+)/[//EMAIL/]/gi;  
str=str.replace(re,"$1"); //电子邮件链接1  
re=//[EMAIL=([/w-]+(/.[/w-]+)*@[/w-]+(/.[/w-]+)+)/](.[^/[]*)/[//EMAIL/]/gi;  
str=str.replace(re,"$4"); //电子邮件链接2  

re=//[img/](.[^/[]*)/[//img/]/gi;  
str=str.replace(re,""); //图片  
re=/:em(/d{1,}):/gi;  
str=str.replace(re,""); //表情图标  
return str;  
}

以上就是一个不错的用JavaScript实现的UBB编码函数的详细内容,更多请关注0133技术站其它相关文章!

赞(0) 打赏
未经允许不得转载:0133技术站首页 » JavaScript 教程

相关文章