• 软件测试技术
  • 软件测试博客
  • 软件测试视频
  • 开源软件测试技术
  • 软件测试论坛
  • 软件测试沙龙
  • 软件测试资料下载
  • 软件测试杂志
  • 软件测试人才招聘
    暂时没有公告

字号: 小 中 大 | 推荐给好友 上一篇 | 下一篇

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

发布: 2007-6-30 18:56 | 作者: admin | 来源: | 查看: 19次 | 进入软件测试论坛讨论

领测软件测试网 <%
‘’ 以前写全文检索程序的时候写的.
‘’ 原创 by 飞鸟@dev-club.com
‘’ Email: [email protected]
‘’ 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
    
%>

文章来源于领测软件测试网 https://www.ltesting.net/


关于领测软件测试网 | 领测软件测试网合作伙伴 | 广告服务 | 投稿指南 | 联系我们 | 网站地图 | 友情链接
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备10010545号-5
技术支持和业务联系:[email protected] 电话:010-51297073

软件测试 | 领测国际 | ISTQB | ISTQB官网 | TMMi | TMMi认证 | 国际软件测试工程师认证 | 领测软件测试网