导航:业界 | 认证 | 工具 | 图形 | 技术 | 系统 | 网络 | 办公 | 网页 | 文摘 | 动画
您当前的位置:diva8.com -> I T -> 技术 -> ASP学院 -> I T内容
栏目导航
· .Net专栏 · Script
· ASP学院 · PHP学院
· Web服务器 · CGI学院
· XML学院 · SQL学院
· JSP学院 · SMS学院
热门I T
· [组图] 音频后期处理Adobe ...
· [组图] Photoshop--照片处理...
· [组图] 廉颇老矣?IE7.0 Bet...
· [图文] DuDu下载加速器推出...
· [组图] 清晰还原!Photoshop...
· [组图] 用photoshop给图片祛...
· [组图] DuDu 下载加速器试用...
· [组图] 新春特别版:PPLIVE...
· [图文] 让查找更方便些 腾讯...
· [组图] 廉颇老矣?IE7.0 Bet...
相关I T
· 使用准则进行条件查...
· [组图] 用Office工具编辑数...
· 正则表达式高级学习...
· 使用正则表达式实现...
· Taglib 原理和实现之...
· C语言初级讲座之运算...
· Asp正则表达式在UB...
· 用正则表达式剔除文...
· 用正则表达式突出显...
· 实现搜索结果的关键...
实现搜索结果的关键词变色标注的程序(使用正则表达式)
作者:Admin  来源:齐昌网络  发布时间:2004-10-12 15:26:44  发布人:qichang

减小字体 增大字体



<%
' 以前写全文检索程序的时候写的.
' 原创 by 飞鸟@dev-club.com
' Email: flybird@dev-club.com
' ie5.5 脚本引擎 required

    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
    
%>


[] [返回上一页] [打 印] [收 藏]
上一篇I T:simple
∷相关I T评论∷    (评论内容只代表网友观点,与本站立场无关!) [更多评论...]
关于本站 - 网站帮助 - 广告合作 - 下载声明 - 友情连接 - 网站地图 - 在线人数:
diva8.com Copyright © 2001-2006 diva8.com All Rights Reserved .粤ICP备05014750号