asp正则替换

稿件来源: 互联网   撰稿作者: 太阳光   发表日期: 2009-06-28 11:14:42   阅读次数: 487   查看权限: 游客查看

asp正则替换

<%
    '示例一个将内容中的邮箱标记转换成html标记的(其实原型是ubb转换函数中)
    Dim strContent : strContent = "原字符串sdfsdf[emails]guangda1234@126.com[/emails]"
    Dim re, strMatchs, strMatch, tmpStr1
    Set re=new RegExp        ' 建立正则表达式。
    re.IgnoreCase =True    ' 设置是否区分大小写。
    re.Global=True
    re.Pattern = "\[emails](.[^\[]*)\[\/emails]"
    Set strMatchs = re.Execute(strContent)
    For Each strMatch in strMatchs
        tmpStr1=strMatch.SubMatches(0)
        '多个标记...strMatch.SubMatches(1)
        strContent=replace(strContent,strMatch.Value,"<a href=""mailto:"&tmpStr1&""">"&tmpStr1&"</a>",1,-1,0)
    Next
%>

简单点的处理方法:
<%
    '功能同上
    Dim Str : Str = "原字符串sdfsdf[emails]guangda1234@126.com[/emails]"
    Dim re    
    Set re=new RegExp    
    re.IgnoreCase =True   
    re.Global=True   
    re.Pattern="\[emails](.[^\[]*)\[\/emails]"   
    Str = re.replace(Str,"<a href=""mailto:""$1"">$1</a>")    
%>
替换动态网页参数
<% 
Function RegUrl(TheStr) 
Set RegEx = New RegExp 
RegEx.IgnoreCase =True 
regEx.Global = True'****这一句加上是全部替换,如果不加,只替换第一个 
RegEx.Pattern = "pic_list_mb\.asp\?id=(\d*)\&page=(\d*)" 
RegUrl=RegEx.replace(TheStr,"pic_list_$1_$2.html")
End Function
content="<ul><li><a href=pic_list_mb.asp?id=1&page=2>动态网址</a></li><li><a href=pic_list_mb.asp?id=32&page=1>动态网址1</a></li</ul>" 
content=RegUrl(content)
response.write content 
%>

关键词: asp正则,asp替换   编辑时间: 2010-09-17

  • 感到高兴

    1

    高兴
  • 感到支持

    0

    支持
  • 感到搞笑

    0

    搞笑
  • 感到不解

    0

    不解
  • 感到谎言

    0

    谎言
  • 感到枪稿

    0

    枪稿
  • 感到震惊

    0

    震惊
  • 感到无奈

    0

    无奈
  • 感到无聊

    0

    无聊
  • 感到反对

    0

    反对
  • 感到愤怒

    0

    愤怒
66.67%(2)
33.33%(1)
共有0 条评论 发言请遵守【相关规定

网友评论

会员头像
发 表同步腾讯微博    验证码:  点击更新请先登陆
  • 暂无评论
关闭模块文章图片 article Pictrue
  • 我的妈妈爸爸
  • 基于koa2+mysql+vue2.0+Element阳光内容管理系统
  • 代码覆盖率工具 Istanbul 入门教程
  • 全栈工程师的武器——MEAN
  • 9款超炫的 CSS3 复选框(Checkbox)
  • 微信开发在线翻译功能
  • CSS3那些不为人知的高级属性
  • 给easyui的datebox添加清空事件
  • flash写字效果
  • kendoUI系列教程之DropDownList下拉菜单
  • kendoUI系列教程之datetimepicker日期时间选择
  • kendoUI系列教程之datepicker日期选择
  • kendoUI系列教程之combobox下拉列表框
  • kendoUI系列教程之colorpicker
  • kendoUI系列教程之calendar日历表
  • kendoUI系列教程之autocomplete自动补齐