Parsing log entries to create a map of error locations within the text.

ID: 830

				
					using uCalcSoftware;

var uc = new uCalc();
var t = new uCalc.Transformer();
t.Text = "[INFO] System boot. [ERROR] Connection failed. [INFO] Retrying...";
t.Pattern("'['ERROR']' {msg}.");
t.Find();

Console.WriteLine($"Found {t.Matches.Count()} error(s):");
foreach(var match in t.Matches) {
   Console.WriteLine($"- '{match.Text}' starts at index {match.StartPosition}");
}
				
			
Found 1 error(s):
- '[ERROR] Connection failed.' starts at index 20
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   uCalc::Transformer t;
   t.Text("[INFO] System boot. [ERROR] Connection failed. [INFO] Retrying...");
   t.Pattern("'['ERROR']' {msg}.");
   t.Find();

   cout << "Found " << t.Matches().Count() << " error(s):" << endl;
   for(auto match : t.Matches()) {
      cout << "- '" << match.Text() << "' starts at index " << match.StartPosition() << endl;
   }
}
				
			
Found 1 error(s):
- '[ERROR] Connection failed.' starts at index 20
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      Dim t As New uCalc.Transformer()
      t.Text = "[INFO] System boot. [ERROR] Connection failed. [INFO] Retrying..."
      t.Pattern("'['ERROR']' {msg}.")
      t.Find()
      
      Console.WriteLine($"Found {t.Matches.Count()} error(s):")
      For Each match In t.Matches
         Console.WriteLine($"- '{match.Text}' starts at index {match.StartPosition}")
      Next
   End Sub
End Module
				
			
Found 1 error(s):
- '[ERROR] Connection failed.' starts at index 20