Finds the global index of a match that was retrieved from a rule-specific match list.
ID: 844
See: IndexOf
using uCalcSoftware;
var uc = new uCalc();
var t = uc.NewTransformer();
var log = "INFO: Task started. ERROR: Connection failed. INFO: Task finished.";
var infoRule = t.Pattern("INFO: {msg}.");
var errorRule = t.Pattern("ERROR: {msg}.");
t.Text = log;
t.Find();
// Get the first match specific to the error rule
var firstErrorMatch = errorRule.Matches[0];
Console.WriteLine($"First error match text: '{firstErrorMatch.Text}'");
// Now, find its index within the global list of all matches
var globalIndex = t.Matches.IndexOf(firstErrorMatch.StartPosition);
Console.WriteLine($"The first error is the match at global index: {globalIndex}");
// Verify by printing the match from the global list
Console.WriteLine($"Global match at that index: '{t.Matches[globalIndex].Text}'");
First error match text: 'ERROR: Connection failed.'
The first error is the match at global index: 1
Global match at that index: 'ERROR: Connection failed.' using uCalcSoftware; var uc = new uCalc(); var t = uc.NewTransformer(); var log = "INFO: Task started. ERROR: Connection failed. INFO: Task finished."; var infoRule = t.Pattern("INFO: {msg}."); var errorRule = t.Pattern("ERROR: {msg}."); t.Text = log; t.Find(); // Get the first match specific to the error rule var firstErrorMatch = errorRule.Matches[0]; Console.WriteLine($"First error match text: '{firstErrorMatch.Text}'"); // Now, find its index within the global list of all matches var globalIndex = t.Matches.IndexOf(firstErrorMatch.StartPosition); Console.WriteLine($"The first error is the match at global index: {globalIndex}"); // Verify by printing the match from the global list Console.WriteLine($"Global match at that index: '{t.Matches[globalIndex].Text}'");
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
auto t = uc.NewTransformer();
auto log = "INFO: Task started. ERROR: Connection failed. INFO: Task finished.";
auto infoRule = t.Pattern("INFO: {msg}.");
auto errorRule = t.Pattern("ERROR: {msg}.");
t.Text(log);
t.Find();
// Get the first match specific to the error rule
auto firstErrorMatch = errorRule.Matches()[0];
cout << "First error match text: '" << firstErrorMatch.Text() << "'" << endl;
// Now, find its index within the global list of all matches
auto globalIndex = t.Matches().IndexOf(firstErrorMatch.StartPosition());
cout << "The first error is the match at global index: " << globalIndex << endl;
// Verify by printing the match from the global list
cout << "Global match at that index: '" << t.Matches()[globalIndex].Text() << "'" << endl;
}
First error match text: 'ERROR: Connection failed.'
The first error is the match at global index: 1
Global match at that index: 'ERROR: Connection failed.' #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; auto t = uc.NewTransformer(); auto log = "INFO: Task started. ERROR: Connection failed. INFO: Task finished."; auto infoRule = t.Pattern("INFO: {msg}."); auto errorRule = t.Pattern("ERROR: {msg}."); t.Text(log); t.Find(); // Get the first match specific to the error rule auto firstErrorMatch = errorRule.Matches()[0]; cout << "First error match text: '" << firstErrorMatch.Text() << "'" << endl; // Now, find its index within the global list of all matches auto globalIndex = t.Matches().IndexOf(firstErrorMatch.StartPosition()); cout << "The first error is the match at global index: " << globalIndex << endl; // Verify by printing the match from the global list cout << "Global match at that index: '" << t.Matches()[globalIndex].Text() << "'" << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
Dim t = uc.NewTransformer()
Dim log = "INFO: Task started. ERROR: Connection failed. INFO: Task finished."
Dim infoRule = t.Pattern("INFO: {msg}.")
Dim errorRule = t.Pattern("ERROR: {msg}.")
t.Text = log
t.Find()
'// Get the first match specific to the error rule
Dim firstErrorMatch = errorRule.Matches(0)
Console.WriteLine($"First error match text: '{firstErrorMatch.Text}'")
'// Now, find its index within the global list of all matches
Dim globalIndex = t.Matches.IndexOf(firstErrorMatch.StartPosition)
Console.WriteLine($"The first error is the match at global index: {globalIndex}")
'// Verify by printing the match from the global list
Console.WriteLine($"Global match at that index: '{t.Matches(globalIndex).Text}'")
End Sub
End Module
First error match text: 'ERROR: Connection failed.'
The first error is the match at global index: 1
Global match at that index: 'ERROR: Connection failed.' Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() Dim t = uc.NewTransformer() Dim log = "INFO: Task started. ERROR: Connection failed. INFO: Task finished." Dim infoRule = t.Pattern("INFO: {msg}.") Dim errorRule = t.Pattern("ERROR: {msg}.") t.Text = log t.Find() '// Get the first match specific to the error rule Dim firstErrorMatch = errorRule.Matches(0) Console.WriteLine($"First error match text: '{firstErrorMatch.Text}'") '// Now, find its index within the global list of all matches Dim globalIndex = t.Matches.IndexOf(firstErrorMatch.StartPosition) Console.WriteLine($"The first error is the match at global index: {globalIndex}") '// Verify by printing the match from the global list Console.WriteLine($"Global match at that index: '{t.Matches(globalIndex).Text}'") End Sub End Module