A practical example showing how to iterate through all matches and print the name of the rule that generated each one for debugging.
ID: 952
See: Name = [string]
using uCalcSoftware;
var uc = new uCalc();
var t = new uCalc.Transformer();
t.Text = "Log: INFO, Data: 123, Log: WARN";
// Define two rules with different starting anchors
t.Pattern("Log: {@Alpha}");
t.Pattern("Data: {@Number}");
t.Find();
Console.WriteLine("--- Match Analysis ---");
foreach(var match in t.Matches) {
Console.WriteLine($"Match '{match.Text}' was found by rule '{match.Rule.Name}'");
}
--- Match Analysis ---
Match 'Log: INFO' was found by rule 'log'
Match 'Data: 123' was found by rule 'data'
Match 'Log: WARN' was found by rule 'log' using uCalcSoftware; var uc = new uCalc(); var t = new uCalc.Transformer(); t.Text = "Log: INFO, Data: 123, Log: WARN"; // Define two rules with different starting anchors t.Pattern("Log: {@Alpha}"); t.Pattern("Data: {@Number}"); t.Find(); Console.WriteLine("--- Match Analysis ---"); foreach(var match in t.Matches) { Console.WriteLine($"Match '{match.Text}' was found by rule '{match.Rule.Name}'"); }
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
uCalc::Transformer t;
t.Text("Log: INFO, Data: 123, Log: WARN");
// Define two rules with different starting anchors
t.Pattern("Log: {@Alpha}");
t.Pattern("Data: {@Number}");
t.Find();
cout << "--- Match Analysis ---" << endl;
for(auto match : t.Matches()) {
cout << "Match '" << match.Text() << "' was found by rule '" << match.Rule().Name() << "'" << endl;
}
}
--- Match Analysis ---
Match 'Log: INFO' was found by rule 'log'
Match 'Data: 123' was found by rule 'data'
Match 'Log: WARN' was found by rule 'log' #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; uCalc::Transformer t; t.Text("Log: INFO, Data: 123, Log: WARN"); // Define two rules with different starting anchors t.Pattern("Log: {@Alpha}"); t.Pattern("Data: {@Number}"); t.Find(); cout << "--- Match Analysis ---" << endl; for(auto match : t.Matches()) { cout << "Match '" << match.Text() << "' was found by rule '" << match.Rule().Name() << "'" << endl; } }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
Dim t As New uCalc.Transformer()
t.Text = "Log: INFO, Data: 123, Log: WARN"
'// Define two rules with different starting anchors
t.Pattern("Log: {@Alpha}")
t.Pattern("Data: {@Number}")
t.Find()
Console.WriteLine("--- Match Analysis ---")
For Each match In t.Matches
Console.WriteLine($"Match '{match.Text}' was found by rule '{match.Rule.Name}'")
Next
End Sub
End Module
--- Match Analysis ---
Match 'Log: INFO' was found by rule 'log'
Match 'Data: 123' was found by rule 'data'
Match 'Log: WARN' was found by rule 'log' Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() Dim t As New uCalc.Transformer() t.Text = "Log: INFO, Data: 123, Log: WARN" '// Define two rules with different starting anchors t.Pattern("Log: {@Alpha}") t.Pattern("Data: {@Number}") t.Find() Console.WriteLine("--- Match Analysis ---") For Each match In t.Matches Console.WriteLine($"Match '{match.Text}' was found by rule '{match.Rule.Name}'") Next End Sub End Module