日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問(wèn)題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
在VB中如何使用正則表達(dá)式

1. 啟動(dòng) Microsoft Visual Basic 6.0。

2. 在“文件”菜單上,單擊“新建項(xiàng)目”。

3. 在“新建項(xiàng)目”對(duì)話框中,單擊“Standard Exe”,然后單擊“確定”。

默認(rèn)情況下將創(chuàng)建 Form1。

4. 在“項(xiàng)目”菜單上單擊“引用”。

5. 雙擊“Microsoft VBScript Regular Expressions 5.5”,然后單擊“確定”。

6. 在工具箱中,雙擊“命令按鈕”。

默認(rèn)情況下,“Command1”將添加到窗體中。

7. 雙擊“Command1”以打開(kāi)代碼窗口。

8. 將下面的代碼粘貼到“Command1_Click”事件處理程序:MsgBox(TestRegExp(“is.”, “IS1 is2 IS3 is4″))

注意 這個(gè)示例中將對(duì)照“IS1 is2 IS3 is4”字符串檢查 is. 模式。您可以將句點(diǎn)這一特殊字符(.)用作通配符,這樣,搜索模式就能夠多匹配并多顯示一個(gè)字符。如果www.x-force.cn您在搜索模式中添加兩個(gè)句點(diǎn),您會(huì)看到兩個(gè)其他字符。如果您不使用任何句點(diǎn),您只會(huì)看到搜索模式。

9. 將以下函數(shù)添加到“Command1_click”事件處理程序后:

  
 
 
  1. [codes=vb]Function TestRegExp(myPattern As String, myString As String)  
  2. ”Create objects.  
  3. Dim objRegExp As RegExp  
  4. Dim objMatch As Match  
  5. Dim colMatches As MatchCollection  
  6. Dim RetStr As String 
  7. ” Create a regular expression object.  
  8. Set objRegExp = New RegExp  
  9. ”Set the pattern by using the Pattern property.  
  10. objRegExp.Pattern = myPattern  
  11. ” Set Case Insensitivity.  
  12. objRegExp.IgnoreCase = True 
  13. ”Set global applicability.  
  14. objRegExp.Global = True 
  15. ”Test whether the String can be compared.  
  16. If (objRegExp.Test(myString) = True) Then 
  17. ”Get the matches.  
  18. Set colMatches = objRegExp.Execute(myString) ” Execute search.  
  19. For Each objMatch In colMatches ” Iterate Matches collection.  
  20. RetStr = RetStr & “Match found at position “  
  21. RetStr = RetStr & objMatch.FirstIndex & “. Match Value is ””  
  22. RetStr = RetStr & objMatch.Value & “”.” & vbCrLf  
  23. Next 
  24. Else 
  25. RetStr = “String Matching Failed”  
  26. End If 
  27. TestRegExp = RetStr  
  28. End Function[/codes] 

10. 在“運(yùn)行”菜單上,單擊“啟動(dòng)”來(lái)運(yùn)行該應(yīng)用程序。

11. 單擊“Command1”。

此時(shí)將出現(xiàn)一個(gè)消息框,該消息顯示 IS1 is2 IS3 is4 字符串中的所有 is 匹配項(xiàng)。

原文鏈接:http://www.cnblogs.com/caiy007/archive/2012/05/08/2489553.html

責(zé)任編輯:彭凡
來(lái)源: 博客園 VB


當(dāng)前名稱:在VB中如何使用正則表達(dá)式
網(wǎng)頁(yè)鏈接:http://www.dlmjj.cn/article/dhjojhc.html