Regex Matches : Regular Expressions « Regular Expressions « VB.Net Tutorial






Imports System.Text.RegularExpressions
Public Class Tester
    Public Shared Sub Main
        Dim quote As String = "AA BB in"
        Dim count1 As Integer
        Dim count2 As Integer
        Dim count3 As Integer
        count1 = Regex.Matches(quote, "(in)+").Count

        count2 = Split(quote, "in").Length - 1

        Dim content As String = "in"

        Dim position As Integer = -content.Length
        Do
            position = quote.IndexOf(content, position + content.Length)
            If (position < 0) Then Exit Do
            count3 += 1
        Loop

        Console.WriteLine(String.Format( _
            "{0}{3}{1}{3}{2}", count1, count2, count3, vbNewLine))    
    
    End Sub

End Class
1
1
1








20.1.Regular Expressions
20.1.1.Regex Matches
20.1.2.Word count
20.1.3.Regex('\w+')
20.1.4.Count chars: Regex.Matches(quote, .)
20.1.5.Word count: Regex.Matches(quote, '\w+')
20.1.6.Count line: Regex.Matches(quote, '.+\n*')
20.1.7.Regex.CompileToAssembly
20.1.8.Match regular expression to string and print out all matches
20.1.9.Using Regex method Replace: substituted for *
20.1.10.Using Regex method Replace: Replace one string with another
20.1.11.Every word replaced by another word
20.1.12.Replace first 3 digits
20.1.13.String split at commas