关于asp截取包含某个字符的一段字符

gueiqi 2008-11-28 12:05:37
例如本站地址:http://www.aaa.com

aaa = "http://www.aaa.com/gfdgf/|http://www.bbb.com/|/about/|aaa|#"

bbb = Split(aaa,"|")

如何最后获得 http://www.bbb.com/ 值

...全文
151 14 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
使用正则!
gueiqi 2008-11-28
  • 打赏
  • 举报
回复
我是要过滤,假如有N个,符合规定的没有固定的

也许是 bbb(1) 也许是 bbb(2)
littlelam 2008-11-28
  • 打赏
  • 举报
回复
bbb(1)
dgboby 2008-11-28
  • 打赏
  • 举报
回复
补一下

call searchqi(str,".+?[^\=]|(http:.+?com)+")
gueiqi 2008-11-28
  • 打赏
  • 举报
回复
这样就可以过滤掉本地的地址,是不是我的法太笨拙了

能够有效的过滤这样的地址 /dfg.asp?url=http://dfgf.com
dgboby 2008-11-28
  • 打赏
  • 举报
回复

function searchqi(st,sd)
dim sheng_url,sheng_time,sheng_title
Set objRegExp1 = New Regexp
objRegExp1.IgnoreCase = True
objRegExp1.Global = True
objRegExp1.Pattern = sd
set mm=objRegExp1.Execute(st)
For i= 0 to mm.count -1
sheng_url=objRegExp1.Replace(mm.item(i),"$1")
'保存数据
'输出数据
response.write sheng_url&"<br>"
'输出结果
'http://www.aaa.com
'http://www.ccc.com

Next
set objRegExp1=nothing

end function


dim str
str="aaa =""/Open.html?u=http://www.bbb.com|http://www.aaa.com/gfdgf/|http://www.ccc.com/|/about/|aaa|#"""
call searchqi(str,".+?[^\=](http:.+?com)+")

gueiqi 2008-11-28
  • 打赏
  • 举报
回复
我换了种方法,先识别http://

然后在根据6楼大哥给的方法用

call searchqi(str,"<a.+?href=""(.+?)""[^\>]*>.+?</a>")

是不是多此一举了
gueiqi 2008-11-28
  • 打赏
  • 举报
回复
象这样的还是无法过滤

/Open.html?u=http://www.bbb.com
dgboby 2008-11-28
  • 打赏
  • 举报
回复


'还有就是www.aaa.com为自己的地址,也想过滤掉 吗?就

call searchqi(str,"(.+?|http:.+?com)+")

'去掉重复的话,就先保存全部数据到数据,取出删除.


gueiqi 2008-11-28
  • 打赏
  • 举报
回复
还有种可能,过滤后的地址,比如有很多重复的
gueiqi 2008-11-28
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 dgboby 的回复:]
VBScript code

function searchqi(st,sd)
dim sheng_url,sheng_time,sheng_title
Set objRegExp1 = New Regexp
objRegExp1.IgnoreCase = True
objRegExp1.Global = True
objRegExp1.Pattern = sd
set mm=objRegExp1.Execute(st)
For i= 0 to mm.count -1
sheng_url=objRegExp1.Replace(mm.item(i),"$1")
'保存数据
'输出数据
res…
[/Quote]

这为大哥的方法不错,但如果

aaa = "http://www.aaa.com/a.asp|http://www.bbb.com/|http://www.bbb.net/|/about/|http://www.aaa.com/gfdgf/"

call searchqi(str,"(http:.+?com)+")

这个就得不到http://www.bbb.net了
还有就是www.aaa.com为自己的地址,也想过滤掉
dgboby 2008-11-28
  • 打赏
  • 举报
回复


function searchqi(st,sd)
dim sheng_url,sheng_time,sheng_title
Set objRegExp1 = New Regexp
objRegExp1.IgnoreCase = True
objRegExp1.Global = True
objRegExp1.Pattern = sd
set mm=objRegExp1.Execute(st)
For i= 0 to mm.count -1
sheng_url=objRegExp1.Replace(mm.item(i),"$1")
'保存数据
'输出数据
response.write sheng_url&"<br>"
'输出结果
'http://www.aaa.com
'http://www.bbb.com

Next
set objRegExp1=nothing

end function


dim str
str="aaa =""http://www.aaa.com/gfdgf/|http://www.bbb.com/|/about/|aaa|#"""
call searchqi(str,"(http:.+?com)+")

0041123 2008-11-28
  • 打赏
  • 举报
回复
aaa = "http://www.aaa.com/gfdgf/|http://www.bbb.com/|/about/|aaa|#"

bbb = Split(aaa,"|")

For i = LBound(bbb) To UBound(bbb)

if bbb(i)="http://www.bbb.com/" then
Response.Write("返回值数组中的元素[" & i & "]:" & bbb(i) & "<br>")
end if
Next


"http://www.bbb.com/" 想要获得的内容可以自己设置
gueiqi 2008-11-28
  • 打赏
  • 举报
回复
楼上的哥哥能不能给出详细写法

28,409

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧