求助:ASP正则表达式匹配赋值

[复制链接]
查看11 | 回复3 | 2010-4-8 22:33:26 | 显示全部楼层 |阅读模式
dim re Set re=New RegExp re.IgnoreCase=True re.Global=True re.Pattern="\/jiaoan[\.\/]*pdf" str=re.Replace(str,"此处为PDF文件地址") re.Pattern="\/jiaoan[\.\/]*\/" str=re.Replace(str,"此处为目录") Set re=Nothing
回复

使用道具 举报

千问 | 2010-4-8 22:33:26 | 显示全部楼层
使用ASP的Replace函数就可以,例如你的字符串在变量STR中:if right(STR,3)="pdf" THENSTR=Replace(STR,"/","此处为PDF文件地址")ELSESTR=Replace(STR,"/","此处为目录")END IF
回复

使用道具 举报

千问 | 2010-4-8 22:33:26 | 显示全部楼层
ct543 似乎是内行网站程序员或者正则表达式高手不过好像不能匹配提问者的要求,正则表达式就先不说了写起来我也头疼,我提供条思路和一个函数先判断有没有pdf 也就是有文件名就直接替换全路径在判断路径 只有路径就替换为目录下面的函数距离正则表达式的使用:Function TestRegExp(strPattern As String, lpString As String) As String 'vbScript省略后面的 As String '定义对象 Dim rExp As RegExp Dim mMatch As Match Dim mColl As MatchCollection Dim strRet As String '创建表达式对象 Set rExp = New RegExp '赋值属性 rExp.Pattern = strPattern rExp.IgnoreCase = True rExp.Global = True '检查字串是否可以匹配 If (rExp.Test(lpString) = True) Then '获取匹配位置 Set mColl = rExp.Execute(lpString) '开始查找
For Each mMatch In mColl
'枚举结果
strRet = strRet & "匹配位置 "
strRet = strRet & mMatch.FirstIndex & ". 匹配结果 ''"
strRet = strRet & mMatch.Value & "''." & vbCrLf
Next Else
strRet = "正则表达式匹配失败!" End If TestRegExp = strRetEnd Function
回复

使用道具 举报

千问 | 2010-4-8 22:33:26 | 显示全部楼层
1. re.Pattern = "/jiaoan(?:/[^/]+)+(?<!pdf)$"2.re.Pattern = "/jiaoan(?:/[^/]+)+pdf$"
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行