str = "aaa[code]bsbs[/code]bbb[code]hello world[/code]cccc…"
re=/(\[code\])/ig
ct=str.match(re).length
for(i=1;i<=ct;i++)
str=str.replace(/(\[code\])([^\[\]\/]*)(\[\/code\])/,"<textarea id='a"+i+"'>$2<\/textarea>");
alert(str);
re=/(\[code\])/ig
ct=str.match(re).length
for(i=1;i<=ct;i++)
str=str.replace(/(\[code\])([^\[\]\/]*)(\[\/code\])/,"<textarea id='a"+i+"'>$2<\/textarea>");
alert(str);
str = str.replace(/\[code\](.*?)\[\/code\]/ig,function($0,$1){
i++;
return "<textarea id='a" + i + "'>" + $1 + "</textarea>";
})
51js上也没有处理这种情况
<% option explicit %>
<!--#include virtual="include/conn.asp"-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- DW6 -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>shawl.qiu template</title>
</head><body>
<%
dim str:str = "aaa[code]bsbs[/code]bbb[code]hello world[/code]cccc…"
Response.Write("<xmp>")
dim re, resub, temp
dim j:j=1
set re=new RegExp
with re
.global=true
.ignoreCase=true
re.pattern="\[code\]"
set resub=re.execute(str)
for each temp in resub
str=replace(str, temp, "<textarea id='a"&j&"'>", 1, 1, 1)
j=j+1
next
re.pattern="\[\/code\]"
str=.replace(str, "</textarea>")
end with
set re=nothing
Response.Write(str)
Response.Write("</xmp>")
%>
</body>
</html>
模板这样..我得改改