A nice UBB coding function with JavaScript implementation _javascript skills

Source: Internet
Author: User

function Jsubb (str)
{
var re=//[i/] (. [ ^/[]*)/[//i/]/gi;
Str=str.replace (Re, "<i>$1</i>"); Italic character
re=//[b/] (. [ ^/[]*)/[//b/]/gi;
Str=str.replace (Re, "<b>$1</b>"); Bold Word
re=//[u/] (. [ ^/[]*)/[//u/]/gi;
Str=str.replace (Re, "<u>$1</u>"); Underline
Re=//[color= (. [ ^/[]*)/](. [^/[]*)/[//color/]/gi;
Str=str.replace (Re, "<font color=$1>$2</font>"); Font Color
Re=//[size= ([1-7])/] (. [ ^/[]*)/[//size/]/gi;
Str=str.replace (Re, "<font size=$1>$2</font>"); Font size
Re=//[face= (. [ ^/[]*)/](. [^/[]*)/[//face/]/gi;
Str=str.replace (Re, "<font face=$1>$2</font>"); Font

Re=//[center/] (. [ ^/[]*)/[//center/]/gi;
Str=str.replace (Re, "<div align= ' center ' >$1</div>"); Center
Re=//[right/] (. [ ^/[]*)/[//right/]/gi;
Str=str.replace (Re, "<div align= ' right ' >$1</div>"); Align Right
re=//[quote/] (. [ ^/[]*)/[//quote/]/gi; Reference
Str=str.replace (Re, "<table bgcolor= ' #E6FFE6 ' width= ' 90% ' style= ' #009900 border:1px ' dotted ' center ' >< TR&GT;&LT;TD class= ' td1 ' >$1</td></tr></table> ');

re=//[fly/] (. *)/[//fly/]/gi; Flight
Str=str.replace (Re, "<marquee width=90% behavior=alternate scrollamount=3>$1</marquee>");
Re=//[move/] (. *)/[//move/]/gi; Move
Str=str.replace (Re, "<marquee scrollamount=3>$1</marquee>");
re=//[shadow=* ([0-9]*), * (#*[a-z0-9]*), * ([0-9]*)/] (. [ ^/[]*)/[//shadow]/gi; Shadow
Str=str.replace (Re, "<table width=$1><tr><td style= ' Filter:shadow" (color=$2, strength=$3) ' >$4< /td></tr></table> ");
re=//[glow=* ([0-9]*), * (#*[a-z0-9]*), * ([0-9]*)/] (. [ ^/[]*)/[//glow]/gi; Outer Glow
Str=str.replace (Re, "<table width=$1 ><tr><td style=" Filter:glow (color=$2, strength=$3) ' >$4</ Td></tr></table> ")

Re=//[url/] (. [ ^/[]*)/[//url/]/gi;
Str=str.replace (Re, "<a href= ' target=_blank>$1</a>"); Hyperlink 1
Re=//[url= (. [ ^/[]*)/](. [^/[]*)/[//url/]/gi;
Str=str.replace (Re, "<a href= ' target=_blank>$2</a>"); Hyperlink 2

re=//[email/] ([/w-]+ (/.[ /w-]+) *@[/w-]+ (/.[ /w-]+) +)/[//email/]/gi;
Str=str.replace (Re, "<a href= ' mailto:$1 ' >$1</a>"); Email Link 1
Re=//[email= ([/w-]+ (/.[ /w-]+) *@[/w-]+ (/.[ /w-]+) +)/] (. [ ^/[]*)/[//email/]/gi;
Str=str.replace (Re, "<a href= ' mailto:$1 ' >$4</a>"); Email Link 2

re=//[img/] (. [ ^/[]*)/[//img/]/gi;
Str=str.replace (Re, "<a href= ' $ target=_blank></a>"); Image
Re=/:em (/d{1,}):/gi;
Str=str.replace (Re, "return str;
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.