摘要:VB.net 活用規則運算式
學會用規則運算式之後,我們要從網頁原始碼擷取文字就變的非常容易
像我最近寫一個小程式 MU網址擷取
就是利用規則運算式取出網頁原始碼中 http://www.megaupload.com 開頭的網址
以下是code
Imports System.IO
Imports System.Text
Imports System.Text.RegularExpressions
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim ex As New Regex("(http|ftp|https):\/\/[\w\-_]+(\.megaupload)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?")
For Each m As Match In ex.Matches(TextBox1.Text)
For Each c As Capture In m.Captures
If c.Value <> "" Then TextBox1.Tag = c.Value + vbCrLf + TextBox1.Tag
Next
Next
TextBox1.Text = TextBox1.Tag
End sub
如有錯誤 歡迎指正