' ' Created by SharpDevelop. ' User: Laimis ' Date: 2013.11.27 ' Time: 00:38 ' ' To change this template use Tools | Options | Coding | Edit Standard Headers. ' Imports System.Text.RegularExpressions Module Program Sub Main() Console.WriteLine("Hello RegExp World!") ' TODO: Implement Functionality Here Console.WriteLine("Press any key to proceed...") Console.ReadKey(True) DisplayTextFile() End Sub Sub DisplayTextFile() Dim sBuffer As String Dim sPattern As String Dim eOptions As RegexOptions = RegexOptions.Multiline Or _ RegexOptions.IgnoreCase Dim dictVars As New Dictionary(Of String, String) Const FILE_PATH As String = "F:\Temp\Printout.txt" If Not System.IO.File.Exists(FILE_PATH) Then Exit Sub Else sBuffer = System.IO.File.ReadAllText(FILE_PATH) End If ' Date/Time sPattern = "\s+(Date|Time):\s+((\d?\d\/\d?\d\/\d\d)|(\d\d:\d\d(AM|PM)))\b" For Each m As Match In Regex.Matches(sBuffer, sPattern, eOptions) 'Console.WriteLine("{0}: {1}", m.Groups(1), m.Groups(2)) dictVars.Add(m.Groups(0).Value, m.Groups(1).Value) Next ' Temperatures: sPattern = "\s+(E[1-4]|D[1-5]|S1|A)\s+(ON|OFF)\s+(\d{1,3}\.\d)\s+(\d{1,3}\.\d)\b" For Each m As Match In Regex.Matches(sBuffer, sPattern, eOptions) 'Console.WriteLine("{0}: {1}, {2}, {3}", m.Groups(1), m.Groups(2), m.Groups(3), m.Groups(4)) dictVars.Add(m.Groups(1).Value + "_On", m.Groups(2).Value) dictVars.Add(m.Groups(1).Value + "_Ts", m.Groups(3).Value) dictVars.Add(m.Groups(1).Value + "_Ta", m.Groups(4).Value) Next ' Other Settings: sPattern = "\s+((Syn-\w+)|(Maschine (Speed|Load))|(Puller \d? ?Speed)|(Prod (Temperature|Pressure ?\d?)))\s+(\d{1,3}\.\d{1,2}\b)" For Each m As Match In Regex.Matches(sBuffer, sPattern, eOptions) 'Console.WriteLine("{0}: {1}", m.Groups(1), m.Groups(8)) dictVars.Add(m.Groups(1).Value, m.Groups(8).Value) Next For Each item In dictVars Console.WriteLine("{0}: {1}", item.Key, item.Value) Next End Sub End Module