A practical example using multiple concurrent patterns to find and categorize log entries.
ID: 1066
See: Find
using uCalcSoftware;
var uc = new uCalc();
var t = new uCalc.Transformer();
var logText = "INFO: System start. WARN: Low disk. ERROR: DB connection failed.";
t.Text = logText;
// Define rules for different log levels
var errorRule = t.Pattern("ERROR: {msg}.");
var warnRule = t.Pattern("WARN: {msg}.");
t.Find();
Console.WriteLine($"Total issues found: {t.Matches.Count()}");
Console.WriteLine("--- Error Matches ---");
Console.WriteLine(errorRule.Matches.Text);
Console.WriteLine("--- Warning Matches ---");
Console.WriteLine(warnRule.Matches.Text);
Total issues found: 2
--- Error Matches ---
ERROR: DB connection failed.
--- Warning Matches ---
WARN: Low disk. using uCalcSoftware; var uc = new uCalc(); var t = new uCalc.Transformer(); var logText = "INFO: System start. WARN: Low disk. ERROR: DB connection failed."; t.Text = logText; // Define rules for different log levels var errorRule = t.Pattern("ERROR: {msg}."); var warnRule = t.Pattern("WARN: {msg}."); t.Find(); Console.WriteLine($"Total issues found: {t.Matches.Count()}"); Console.WriteLine("--- Error Matches ---"); Console.WriteLine(errorRule.Matches.Text); Console.WriteLine("--- Warning Matches ---"); Console.WriteLine(warnRule.Matches.Text);
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
uCalc::Transformer t;
auto logText = "INFO: System start. WARN: Low disk. ERROR: DB connection failed.";
t.Text(logText);
// Define rules for different log levels
auto errorRule = t.Pattern("ERROR: {msg}.");
auto warnRule = t.Pattern("WARN: {msg}.");
t.Find();
cout << "Total issues found: " << t.Matches().Count() << endl;
cout << "--- Error Matches ---" << endl;
cout << errorRule.Matches().Text() << endl;
cout << "--- Warning Matches ---" << endl;
cout << warnRule.Matches().Text() << endl;
}
Total issues found: 2
--- Error Matches ---
ERROR: DB connection failed.
--- Warning Matches ---
WARN: Low disk. #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; uCalc::Transformer t; auto logText = "INFO: System start. WARN: Low disk. ERROR: DB connection failed."; t.Text(logText); // Define rules for different log levels auto errorRule = t.Pattern("ERROR: {msg}."); auto warnRule = t.Pattern("WARN: {msg}."); t.Find(); cout << "Total issues found: " << t.Matches().Count() << endl; cout << "--- Error Matches ---" << endl; cout << errorRule.Matches().Text() << endl; cout << "--- Warning Matches ---" << endl; cout << warnRule.Matches().Text() << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
Dim t As New uCalc.Transformer()
Dim logText = "INFO: System start. WARN: Low disk. ERROR: DB connection failed."
t.Text = logText
'// Define rules for different log levels
Dim errorRule = t.Pattern("ERROR: {msg}.")
Dim warnRule = t.Pattern("WARN: {msg}.")
t.Find()
Console.WriteLine($"Total issues found: {t.Matches.Count()}")
Console.WriteLine("--- Error Matches ---")
Console.WriteLine(errorRule.Matches.Text)
Console.WriteLine("--- Warning Matches ---")
Console.WriteLine(warnRule.Matches.Text)
End Sub
End Module
Total issues found: 2
--- Error Matches ---
ERROR: DB connection failed.
--- Warning Matches ---
WARN: Low disk. Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() Dim t As New uCalc.Transformer() Dim logText = "INFO: System start. WARN: Low disk. ERROR: DB connection failed." t.Text = logText '// Define rules for different log levels Dim errorRule = t.Pattern("ERROR: {msg}.") Dim warnRule = t.Pattern("WARN: {msg}.") t.Find() Console.WriteLine($"Total issues found: {t.Matches.Count()}") Console.WriteLine("--- Error Matches ---") Console.WriteLine(errorRule.Matches.Text) Console.WriteLine("--- Warning Matches ---") Console.WriteLine(warnRule.Matches.Text) End Sub End Module