當前位置: 首頁>>代碼示例>>VB.NET>>正文


VB.NET Regex.Matches方法代碼示例

本文整理匯總了VB.NET中System.Text.RegularExpressions.Regex.Matches方法的典型用法代碼示例。如果您正苦於以下問題:VB.NET Regex.Matches方法的具體用法?VB.NET Regex.Matches怎麽用?VB.NET Regex.Matches使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Text.RegularExpressions.Regex的用法示例。


在下文中一共展示了Regex.Matches方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。

示例1: Example

' 導入命名空間
Imports System.Text.RegularExpressions

Module Example
   Public Sub Main()
      Dim pattern As String = "\b\w+es\b"
      Dim rgx As New Regex(pattern)
      Dim sentence As String = "Who writes these notes?"
      
      For Each match As Match In rgx.Matches(sentence)
         Console.WriteLine("Found '{0}' at position {1}", match.Value, match.Index)
      Next
   End Sub
End Module
開發者ID:VB.NET開發者,項目名稱:System.Text.RegularExpressions,代碼行數:14,代碼來源:Regex.Matches

輸出:

Found 'writes' at position 4
Found 'notes' at position 17

示例2:

Dim match As Match = regex.Match(input)
Do While match.Success
      ' Handle match here...

      match = match.NextMatch()
Loop
開發者ID:VB.NET開發者,項目名稱:System.Text.RegularExpressions,代碼行數:6,代碼來源:Regex.Matches

示例3: Example

' 導入命名空間
Imports System.Text.RegularExpressions

Module Example
   Public Sub Main()
      Dim pattern As String = "\b\w+es\b"
      Dim rgx As New Regex(pattern)
      Dim sentence As String = "Who writes these notes and uses our paper?"
      
      ' Get the first match.
      Dim match As Match = rgx.Match(sentence)
      If match.Success Then
         Console.WriteLine("Found first 'es' in '{0}' at position {1}", _
                           match.Value, match.Index)
         ' Get any additional matches.
         For Each match In rgx.Matches(sentence, match.Index + match.Length)
            Console.WriteLine("Also found '{0}' at position {1}", _
                              match.Value, match.Index)
         Next
      End If   
   End Sub
End Module
開發者ID:VB.NET開發者,項目名稱:System.Text.RegularExpressions,代碼行數:22,代碼來源:Regex.Matches

輸出:

Found first 'es' in 'writes' at position 4
Also found 'notes' at position 17
Also found 'uses' at position 27

示例4:

Dim match As Match = regex.Match(input, startAt)
Do While match.Success
      ' Handle match here...

      match = match.NextMatch()
Loop
開發者ID:VB.NET開發者,項目名稱:System.Text.RegularExpressions,代碼行數:6,代碼來源:Regex.Matches

示例5: Example

' 導入命名空間
Imports System.Text.RegularExpressions

Module Example
   Public Sub Main()
      Dim pattern As String = "\b\w+es\b"
      Dim sentence As String = "Who writes these notes?"
      For Each match As Match In Regex.Matches(sentence, pattern)
         Console.WriteLine("Found '{0}' at position {1}", match.Value, match.Index)
      Next
   End Sub
End Module
開發者ID:VB.NET開發者,項目名稱:System.Text.RegularExpressions,代碼行數:12,代碼來源:Regex.Matches

輸出:

Found 'writes' at position 4
Found 'notes' at position 17

示例6:

Dim match As Match = Regex.Match(input, pattern)
Do While match.Success
      ' Handle match here...

      match = match.NextMatch()
Loop
開發者ID:VB.NET開發者,項目名稱:System.Text.RegularExpressions,代碼行數:6,代碼來源:Regex.Matches

示例7: Example

' 導入命名空間
Imports System.Text.RegularExpressions

Module Example
   Public Sub Main()
      Dim pattern As String = "\b\w+es\b"
      Dim sentence As String = "NOTES: Any notes or comments are optional."
      
      ' Call Matches method without specifying any options.
      For Each match As Match In Regex.Matches(sentence, pattern)
         Console.WriteLine("Found '{0}' at position {1}", match.Value, match.Index)
      Next
      Console.WriteLine()
      
      ' Call Matches method for case-insensitive matching.
      For Each match As Match In Regex.Matches(sentence, pattern, RegexOptions.IgnoreCase)
         Console.WriteLine("Found '{0}' at position {1}", match.Value, match.Index)
      Next
   End Sub
End Module
開發者ID:VB.NET開發者,項目名稱:System.Text.RegularExpressions,代碼行數:20,代碼來源:Regex.Matches

輸出:

Found 'notes' at position 11

Found 'NOTES' at position 0
Found 'notes' at position 11

示例8:

Dim match As Match = Regex.Match(input, pattern, options)
Do While match.Success
      ' Handle match here...

      match = match.NextMatch()
Loop
開發者ID:VB.NET開發者,項目名稱:System.Text.RegularExpressions,代碼行數:6,代碼來源:Regex.Matches

示例9: Example

' 導入命名空間
Imports System.Text.RegularExpressions

Module Example
   Public Sub Main()
      Dim pattern As String = "\b\w+es\b"
      Dim sentence As String = "NOTES: Any notes or comments are optional."
      
      ' Call Matches method without specifying any options.
      For Each match As Match In Regex.Matches(sentence, pattern, 
                                               RegexOptions.None, 
                                               TimeSpan.FromSeconds(1))
         Try
            Console.WriteLine("Found '{0}' at position {1}", match.Value, match.Index)
         Catch e As RegexMatchTimeoutException
            ' Do Nothing: Assume that timeout represents no match.
         End Try
      Next
      Console.WriteLine()
      
      ' Call Matches method for case-insensitive matching.
      Try
         For Each match As Match In Regex.Matches(sentence, pattern, 
                                                  RegexOptions.IgnoreCase,
                                                  TimeSpan.FromSeconds(1))
            Console.WriteLine("Found '{0}' at position {1}", match.Value, match.Index)
         Next
      Catch de As RegexMatchTimeoutException
         ' Do Nothing: Assume that timeout represents no match.
      End Try
   End Sub
End Module
開發者ID:VB.NET開發者,項目名稱:System.Text.RegularExpressions,代碼行數:32,代碼來源:Regex.Matches

輸出:

Found 'notes' at position 11

Found 'NOTES' at position 0
Found 'notes' at position 11

示例10:

Try
      Dim match As Match = Regex.Match(input, pattern, options, 
                                       TimeSpan.FromSeconds(1))
      Do While match.Success
            ' Handle match here...

            match = match.NextMatch()
      Loop  
   Catch e As RegexMatchTimeoutException
      ' Do nothing: assume that exception represents no match.
   End Try
開發者ID:VB.NET開發者,項目名稱:System.Text.RegularExpressions,代碼行數:11,代碼來源:Regex.Matches

示例11: Tester

' 導入命名空間
Imports System.Text.RegularExpressions

Public Class Tester
    Public Shared Sub Main
        Dim source As String = "This 7. several 0.9 numbers"
        Dim parser As New Regex( _
           "[-+]?([0-9]*\.)?[0-9]+([eE][-+]?[0-9]+)?")
        Dim sourceMatches As MatchCollection = parser.Matches(source)
        Dim result As Double = CDbl(sourceMatches(1).Value)
        Console.WriteLine(result.ToString())
    End Sub


End Class
開發者ID:VB程序員,項目名稱:System.Text.RegularExpressions,代碼行數:15,代碼來源:Regex.Matches


注:本文中的System.Text.RegularExpressions.Regex.Matches方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。