快精灵印艺坊 您身边的文印专家
广州名片 深圳名片 会员卡 贵宾卡 印刷 设计教程
产品展示 在线订购 会员中心 产品模板 设计指南 在线编辑
 首页 名片设计   CorelDRAW   Illustrator   AuotoCAD   Painter   其他软件   Photoshop   Fireworks   Flash  

 » 彩色名片
 » PVC卡
 » 彩色磁性卡
 » 彩页/画册
 » 个性印务
 » 彩色不干胶
 » 明信片
   » 明信片
   » 彩色书签
   » 门挂
 » 其他产品与服务
   » 创业锦囊
   » 办公用品
     » 信封、信纸
     » 便签纸、斜面纸砖
     » 无碳复印纸
   » 海报
   » 大篇幅印刷
     » KT板
     » 海报
     » 横幅

实现搜索结果的要害词变色标注的程序(使用正则表达式)

<%
dim patern
dim found

dim str
dim result

patern="(a)|(b)"
str=" A dog fall in love with a cat. Can you believe?"
result=""
call getMatchText(str,result,false)
Response.Write result

sub getMatchText(byref str,byref result,isNeedTrunc)
\\\'on error resume next
Dim regEx, Match, Matches
dim tStr
Set regEx = New RegExp \\\' 建立正则表达式。
regEx.Pattern = (patern) \\\' 设置模式。
regEx.IgnoreCase = True \\\' 设置是否区分字符大小写。
regEx.Global = True \\\' 设置全局可用性。
Set Matches = regEx.Execute(str) \\\' 执行搜索。
if err.number<>0 then
response.write "错误1:" & err.description
err.clear
exit sub
end if
if matches.count <>0 then
dim startIndex
dim myMatchValue
startIndex=1
for each match in matches
if (instr(str,match.value)>0) then
if instr(str,match.value)-50 >0 then
startIndex=instr(str,match.value)-50
else
startIndex=1
end if
myMatchValue=match.value
exit for
end if
next
if isNeedTrunc then
result= (mid(str,startIndex,strLength(myMatchValue)+100))
else
result= (str)
end if
for each match in matches
if not(instr(result,"<font color=red>" & match.value & "</font>")>0) then
result=replace(result,match.value,"<font color=red>" & match.value & "</font>" )
end if
next
found=true
else
found=false
end if
set regEx=nothing
end sub

%>
返回类别: 教程
上一教程: 一个通过DATASET操作XML的类
下一教程: 关于在ASP中使用INCLUDE的一些问题

您可以阅读与"实现搜索结果的要害词变色标注的程序(使用正则表达式)"相关的教程:
· 使用正则表达式实现模式图片新闻.ASP
· 用正则表达式搜索电子邮件
· 通过几个异常实用的例子了解ASP中使用正则表达式
· 在ASP中利用“正则表达式” 对象实现UBB风格的论坛
· 用正则表达式突出显示字符串中查询到的单词的函数
    微笑服务 优质保证 索取样品