Here we have a log file, contained in log.txt, and we access this in the StreamReader when we create it. We create a Regex that matches a certain URL pattern.
Imports System.IO
Imports System.Text.RegularExpressions
Module Module1
Sub Main()
' Create Regex.
Dim regex As Regex = New Regex(
"\s/Content/([a-zA-Z0-9\-]+?)\.aspx")
' Loop over the lines in this text file.
Using reader As StreamReader = New StreamReader(
"C:\programs\log.txt")
While (True)
Dim line As String = reader.ReadLine()
' End if Nothing.
If line = Nothing Then
Return
End If
' Try to match.
Dim match As Match = regex.Match(line)
If match.Success Then
' Get first group and print it.
Dim value As String = match.Groups(1).Value
Console.WriteLine(line)
Console.WriteLine(
"... " + value)
End If
End While
End Using
End Sub
End Module
2008-10-16 23:56:44 W3SVC2915713 GET /Content/String.aspx - 80 66.249
2008-10-16 23:59:50 W3SVC2915713 GET /Content/Trim-String-Regex.aspx - 80 66.249
2008-10-16 23:56:44 W3SVC2915713 GET /Content/String.aspx - 80 66.249
... String
2008-10-16 23:59:50 W3SVC2915713 GET /Content/Trim-String-Regex.aspx - 80 66.249
... Trim-String-Regex