欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

asp自动补全html标签自动闭合(正则表达式)

程序员文章站 2022-08-06 17:34:16
复制代码 代码如下: function closehtml(strcontent) dim arrtags, i, openpos, closepos, re, strma...
复制代码 代码如下:

function closehtml(strcontent)
dim arrtags, i, openpos, closepos, re, strmatchs, j, match
set re = new regexp
re.ignorecase = true
re.global = true
arrtags = array("p", "div", "span", "table", "ul", "font", "b", "u", "i", "h1", "h2", "h3", "h4", "h5", "h6")
for i = 0 to ubound(arrtags)
openpos = 0
closepos = 0


re.pattern = "\<" + arrtags(i) + "( [^\<\>]+|)\>"
set strmatchs = re.execute(strcontent)
for each match in strmatchs
openpos = openpos + 1
next
re.pattern = "\</" + arrtags(i) + "\>"
set strmatchs = re.execute(strcontent)
for each match in strmatchs
closepos = closepos + 1
next
for j = 1 to openpos - closepos
strcontent = strcontent + "</" + arrtags(i) + ">"
next
next
closehtml = strcontent
end function