2011年7月28日木曜日

→→→正規検索

Dim r As New Regex("<p>(.*?),/p.")
Dim m As Match = r.Match( source )
while m.success
     m = m.NextMatch()
End while

----------------------------------------------

Dim r As RegEx
Dim m As Match
r = New RegEx( パターン文字列 )
m = r.Match( 検索対象の文字列 )
while m.success
     m = m.NextMatch()  '見つかった文字列に対する処理
End while


123abc1456abc 
 (23a)  (456a)だけを抜く

Dim i As Integer
Dim r As New Regex(" 1(.*?)bc1(.*?)b" )
Dim m As Match( "123abc1456abc" )
While Not ( m.Group(i).Value = "" )
           MsgBox( m.Group(i).Value, , i )
           i += 1
End While

-----------------------------------------

Dim results(20) As String
Dim As Integer
Dim j As New Regex( "<.*?""(.*?)"".*?>" )
Dim m As Match
m = r.Match( " <tr></tr><a href=""/news/****/.html""abcdwxyz</tr>\n<tr/>")
While not (m.Group(i).Value =  "")
     results(i) = m.Groups(i).Value
     MsgBox(results(i), , i)
End While


-----------------------------------------

位置を見つける(発見位置が2番目なのに1番目となるから注意)
Dim text1 As String = "テ"
Dim text2 As String = "イクテス"
Dim As New System.Text.RegularExpressions.Regex(text1)
Dim m As System.Text.RegularExpressions.Match = r.Match( text2 )
If m.Success Then
   MsgBox("Found match at position "& m.Index.ToString())   
End If

0 件のコメント:

コメントを投稿