Look at this example:
The general UBB is difficult to solve the nesting of UBB elements "[xx]".
This problem is completely solved using JScript5.5.
The premise is that in the UBB text, nesting is formal, otherwise it will affect the analysis of nested internals.
VAR thistr = "[b] A1 [b] A2 [b] center [/ b] b2 [/ b] b1 [/ b]"; function normalubb (str) {if (Typeof (STR)! = "string") Str = STR ""; str = str.replace (/ (/ [b /]) (.*) (/ // b /]) / gi, " $ 2 b>"); Return Str } function lostinetubb (STR) {IF (TypeOf (STR)! = "String") Str = Str ""; str = str.replace (/(/ //]) (.*) (/[//b /]) / GI, FUNCTION (STR, POS, RAW) {RETURN LOSTINETUBB (Str.Replace (/ (/ [b /] )(//////]) / gi, " $ 2 b> "));}); Return Str;} Alert (Normalubb (theSTR)); Alert (Lostinetubb (TheStr));