当前位置: 移动技术网 > IT编程>开发语言>Asp > asp 关键词高亮显示(不区分大小写)

asp 关键词高亮显示(不区分大小写)

2017年12月12日  | 移动技术网IT编程  | 我要评论
在这种配置下我们要实现关键词不区分大小写搜索并高亮显示要借助asp的正则处理了,请看下面代码:
复制代码 代码如下:

<%
function takeout(patrn,string1,colors)
'提取搜索关键字匹配文字
dim regex, match, matches, tt ' 建立变量。
set regex = new regexp ' 建立正则表达式。
regex.pattern = patrn ' 设置模式。
regex.ignorecase = true ' 设置是否区分大小写。
regex.global = true ' 设置全局可用性。
set matches = regex.execute(string1) ' 执行搜索。
for each match in matches ' 遍历 matches 集合。
retstr = retstr & match.value & " "
next
retstr = trim(retstr)
if instr(retstr," ")>0 then
for tt = 0 to ubound(split(retstr," "))
string1 = replace(string1,split(retstr," ")(tt),"<font color="""&colors&""">"&split(retstr," ")(tt)&"</font>")
next
else
string1 = replace(string1,retstr,"<font color="""&colors&""">"&retstr&"</font>")
end if
takeout = string1
end function
response.write takeout("joekoe", "joekoe乔客双语版","red")
function highlight(strcontent,keyword) '标记高亮关键字
dim regex
set regex=new regexp
regex.ignorecase =true '不区分大小写
regex.global=true
dim arraykeyword,i
arraykeyword = split(keyword," ")'用空格隔开的多关键字
for i=0 to ubound(arraykeyword)
regex.pattern="("&arraykeyword(i)&")"
strcontent=regex.replace(strcontent,"<font color=red>$1</font>" )
next
set regex=nothing
highlight=strcontent
end function
response.write highlight("joekoe乔客双语版","joekoe")
%>

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网