A good UBB encoding function _ JavaScript technique implemented using javascript

Source: Internet
Author: User
A good UBB coding function implemented in JavaScript: function JsUBB (str)
{
Var re = // [I/] (. [^/[] *)/[// I/]/gi;
Str = str. replace (re ," $1"); // Italics
Re = // [B/] (. [^/[] *)/[// B/]/gi;
Str = str. replace (re ," $1"); // Bold
Re = // [u/] (. [^/[] *)/[// u/]/gi;
Str = str. replace (re ," $1"); // Underline
Re = // [color = (. [^/[] *)/] (. [^/[] *)/[// color/]/gi;
Str = str. replace (re, "$2"); // font color
Re = // [size = ([1-7])/] (. [^/[] *)/[// size/]/gi;
Str = str. replace (re, "$2"); // font size
Re = // [face = (. [^/[] *)/] (. [^/[] *)/[// face/]/gi;
Str = str. replace (re, "$2"); // font

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

$1

"); // Center
Re = // [right/] (. [^/[] *)/[// right/]/gi;
Str = str. replace (re ,"

$1

"); // Right alignment
Re = // [quote/] (. [^/[] *)/[// quote/]/gi; // reference
Str = str. replace (re ,"
$1
");

Re = // [fly/] (. *)/[// fly/]/gi; // flight
Str = str. replace (re ," $1 ");
Re = // [move/] (. *)/[// move/]/gi; // move
Str = str. replace (re ," $1 ");
Re = // [SHADOW = * ([0-9] *), * (# * [a-z0-9] *), * ([0-9] *)/] (. [^/[] *)/[// SHADOW]/gi; // SHADOW
Str = str. replace (re ,"
$4
");
Re = // [GLOW = * ([0-9] *), * (# * [a-z0-9] *), * ([0-9] *)/] (. [^/[] *)/[// GLOW]/gi; // outshines
Str = str. replace (re ,"
$4
")

Re = // [URL/] (. [^/[] *)/[// URL/]/gi;
Str = str. replace (re, "$1"); // hyperlink 1
Re = // [URL = (. [^/[] *)/] (. [^/[] *)/[// URL/]/gi;
Str = str. replace (re, "$2"); // hyperlink 2

Re = // [EMAIL/] ([/w-] + (/. [/w-] +) * @ [/w-] + (/. [/w-] +)/[// EMAIL/]/gi;
Str = str. replace (re, "$1"); // email link 1
Re = // [EMAIL = ([/w-] + (/. [/w-] +) * @ [/w-] + (/. [/w-] +)/] (. [^/[] *)/[// EMAIL/]/gi;
Str = str. replace (re, "$4"); // email link 2

Re = // [img/] (. [^/[] *)/[// img/]/gi;
Str = str. replace (re, ""); // picture
Re =/: em (/d {1,}):/gi;
Str = str. replace (re, ""); // emoticon icon
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.