JScript5.5 String.Prototype.Replace (STR, FUNC) UBB nested recursive unstoppable recursion.

zhaozj2021-02-17  49

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 "); 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 "));}); Return Str;} Alert (Normalubb (theSTR)); Alert (Lostinetubb (TheStr));

转载请注明原文地址:https://www.9cbs.com/read-28509.html

New Post(0)