|  | 主题:  问一个提取部分源码的问题? | 
            
                        
                
                    |  tonest
 职务:普通成员
 等级:1
 金币:0.0
 发贴:177
 注册:2002/4/14 13:32:27
 
 | 
                            
                            #12006/3/3 16:28:12 
                                例如:%^$^%$^##^&^**<-webconment->123456</-webconment->%^$^%$^##^&^**(
 
 请问如何将其中的123456提取出来,或者说将<-webconment->和</-webconment->之间的内容提取出来
 
 有很多网页需要提取这样的内容,如果一页一页的复制,需要处理好几天,困惑了很久,那位高手能提示一下,谢谢!
 | 
                        
                
                    |  缺缺
 职务:管理员
 等级:8
 金币:41.0
 发贴:9620
 注册:2004/1/14 19:14:47
 
 | 
                            
                            #22006/3/3 16:35:01 
                                正则表达式用来干这个就很合适
                                
                                
                                
                             | 
                        
                
                    |  tonest
 职务:普通成员
 等级:1
 金币:0.0
 发贴:177
 注册:2002/4/14 13:32:27
 
 | 
                            
                            #32006/3/3 16:40:36 
                                “正则表达式”学的不精,给个例子好不好?
                                
                                
                                
                             | 
                        
                
                    |  蓝鲸
 职务:版主
 等级:5
 金币:42.1
 发贴:2614
 注册:2001/12/20 15:57:57
 
 |  | 
                        
                
                    |  浮尘
 职务:普通成员
 等级:3
 金币:7.0
 发贴:1258
 注册:2001/11/19 12:41:09
 
 | 
                            
                            #52006/3/4 12:44:41 
                                我自己写的一个函数(ASP),看看能不能用得上。 
	'读取字符串中指定标签的内容,如果有多个指定的标签,则返回第一个标签的内容
	Function GetTagText(Str,TagName)
		Dim RegEx,Matches
		Set RegEx = New RegExp
		RegEx.Global = True
		RegEx.IgnoreCase = True
		RegEx.Pattern = "<" & TagName & ">[\s\S]*?</" & TagName & ">"
		Set Matches= RegEx.Execute(Str)
		If Matches.Count>0 Then
			GetTagText=Mid(Matches(0),Len(TagName)+3,Len(Matches(0))-(Len(TagName)*2+5))
		Else
			GetTagText=""
		End If
	End Function
	'设置字符串中指定标签的内容
	Function SetTagText(Str,TagName,Fill)
		Dim RegEx
		Set RegEx = New RegExp
		RegEx.Global = True
		RegEx.IgnoreCase = True
		RegEx.Pattern = "<" & TagName & ">[\s\S]*?</" & TagName & ">"
		Fill = "<" & TagName & ">" & Fill & "</" & TagName & ">"
		SetTagText=RegEx.Replace(Str,Fill)
	End Function
 | 
                        
                
                    |  Dreaming
 职务:普通成员
 等级:1
 金币:10.0
 发贴:1518
 注册:2004/7/18 17:48:40
 
 | 
                            
                            #62006/3/4 16:49:26 
                                本来是今天上午发的,但是由于论坛有问题,发不到,现在补发 to 楼主:(asp.net 2.0) 
        string strMy;
        int intBegin;
        int intEnd;
        strMy = "abcdefg<-webconment->123456</-webconment->abcd";
        intBegin = strMy.IndexOf("<-webconment->")+14;
        intEnd = strMy.IndexOf("</-webconment->");
        TextBox1.Text = strMy.Substring(intBegin,intEnd-intBegin);
至于正则表达式,我觉得.net还是用.net的验证RegularExpressionValidator比较好,MS虽然提供了一系列被誉为“白痴化”的东西,但无可否认,它大大的提高开发速度……
                                
                                
                                
                             | 
                        
                
                    |  tonest
 职务:普通成员
 等级:1
 金币:0.0
 发贴:177
 注册:2002/4/14 13:32:27
 
 | 
                            
                            #72006/3/5 14:52:30 
                                非常感谢以上各位的热心帮助!    |