asp 关键词高亮显示(不区分大小写)
来源:asp之家 时间:2011-04-07 10:55:00
在这种配置下我们要实现关键词不区分大小写搜索并高亮显示要借助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")
%>
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
利用JavaScript实现防抖节流函数的示例代码
![](https://img.aspxhome.com/file/2023/4/126174_0s.png)
oracle 字符串转成行
OBJECTPROPERTY与sp_rename更改对象名称的介绍
PHP垃圾回收机制超详细介绍
![](https://img.aspxhome.com/file/2023/4/106324_0s.png)
Python文件操作,open读写文件,追加文本内容实例
Golang 统计字符串中数字字母数量的实现方法
Python真题案例之最长回文子串 周期串详解
![](https://img.aspxhome.com/file/2023/2/135442_0s.png)
SQL 中的For Xml Path详解
![](https://img.aspxhome.com/file/2023/4/108514_0s.png)
OpenCV学习记录python实现连通域处理函数
![](https://img.aspxhome.com/file/2023/9/98819_0s.png)
Mysql导入TXT文件
使用url_helper简化Python中Django框架的url配置教程
SQL语句 一个简单的字符串分割函数
归纳整理Python中的控制流语句的知识点
sql删除重复数据的详细方法
SQL语句练习实例之一——找出最近的两次晋升日期与工资额
IDEA 2020 设置项目集成git 及svn和git之间的切换问题
![](https://img.aspxhome.com/file/2023/0/132360_0s.jpg)
Python 多进程、多线程效率对比
Vue3通过ref操作Dom元素及hooks的使用方法
![](https://img.aspxhome.com/file/2023/4/133004_0s.png)
Python利用Xpath选择器爬取京东网商品信息
![](https://img.aspxhome.com/file/2023/4/79554_0s.jpg)