uCalc API Version: 2.1.3-preview.2 Released: 6/16/2026
Warning
uCalc API Preview Release Notice:The documentation describes the intended behavior of the API. The current preview build contains incomplete features, unoptimized performance, and is subject to breaking changes.
GetMatches
Method
Product:
Class:
Retrieves the collection of matches from a Transformer operation, with options to filter the result set.
Syntax
Parameters
Return
Matches
A Matches object containing the collection of matches, filtered according to the provided options.
Remarks
🎯 Retrieving Filtered Match Results
The GetMatches method retrieves the Matches collection generated by the most recent Transformer operation (e.g., Find()). Its key feature is the ability to filter the result set on-the-fly, providing different views of the data without needing to re-run the initial search.
GetMatches() vs. Matches Property
This method is the counterpart to the simpler Matches property. The property is a convenient shortcut for retrieving all matches, equivalent to calling GetMatches(MatchesOption::All). You must use the GetMatches() method when you need to apply any of the advanced filtering options.
⚙️ Filtering with MatchesOption
The behavior of GetMatches is controlled by the options parameter, which accepts a member of the MatchesOption enum:
| Option | Description |
|---|---|
MatchesOption::All (Default) | Returns all matches found by the Transformer operation. |
MatchesOption::FocusableOnly | Filters the list to include only matches from rules marked as focusable (e.g., with Rule.Focusable(true)). |
MatchesOption::RootLevelOnly | In a nested match hierarchy created by a LocalTransformer, this returns only the top-level (parent) matches. |
MatchesOption::InnermostOnly | The opposite of RootLevelOnly; filters the list to include only the most deeply nested (child) matches. |
💡 Why uCalc? (Comparative Analysis)
In a language like C#, developers might filter a collection of results using LINQ:
// C# LINQ examplevar focusableMatches = allMatches.Where(m => m.Rule.IsFocusable).ToList();This approach is stateless and creates a new collection. uCalc's model is different and offers unique advantages:
- Stateful & In-Place: Methods like Matches.Reset() can modify the
Matchescollection in-place, which can be more memory-efficient. - Engine-Side Filtering: The filtering logic is executed inside the highly optimized uCalc engine, which is generally faster than performing the filtering in host application code.
- Declarative API: The
MatchesOptionenum provides a direct and declarative way to ask for a specific view of the data, leading to cleaner and more readable code.
Examples
Demonstrates the basic difference between getting all matches and filtering for only 'focusable' ones.
using uCalcSoftware;
var uc = new uCalc();
var t = new uCalc.Transformer();
t.Text = "ID:100, Name:Admin, ID:200";
// Define two rules, but only one is marked as 'focusable'
t.Pattern("ID:{@Number}").SetFocusable(true);
t.Pattern("Name:{@Alpha}").SetFocusable(false);
t.Find();
// Get all matches using the default option
var allMatches = t.GetMatches();
Console.WriteLine($"--- All Matches ({allMatches.Count()}) ---");
Console.WriteLine(allMatches.Text);
// Get only the focusable matches
var focusableMatches = t.GetMatches(MatchesOption.FocusableOnly);
Console.WriteLine("");
Console.WriteLine($"--- Focusable Matches Only ({focusableMatches.Count()}) ---");
Console.WriteLine(focusableMatches.Text);
--- All Matches (3) ---
ID:100
Name:Admin
ID:200
--- Focusable Matches Only (2) ---
ID:100
ID:200 using uCalcSoftware; var uc = new uCalc(); var t = new uCalc.Transformer(); t.Text = "ID:100, Name:Admin, ID:200"; // Define two rules, but only one is marked as 'focusable' t.Pattern("ID:{@Number}").SetFocusable(true); t.Pattern("Name:{@Alpha}").SetFocusable(false); t.Find(); // Get all matches using the default option var allMatches = t.GetMatches(); Console.WriteLine($"--- All Matches ({allMatches.Count()}) ---"); Console.WriteLine(allMatches.Text); // Get only the focusable matches var focusableMatches = t.GetMatches(MatchesOption.FocusableOnly); Console.WriteLine(""); Console.WriteLine($"--- Focusable Matches Only ({focusableMatches.Count()}) ---"); Console.WriteLine(focusableMatches.Text);
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
uCalc::Transformer t;
t.Text("ID:100, Name:Admin, ID:200");
// Define two rules, but only one is marked as 'focusable'
t.Pattern("ID:{@Number}").SetFocusable(true);
t.Pattern("Name:{@Alpha}").SetFocusable(false);
t.Find();
// Get all matches using the default option
auto allMatches = t.GetMatches();
cout << "--- All Matches (" << allMatches.Count() << ") ---" << endl;
cout << allMatches.Text() << endl;
// Get only the focusable matches
auto focusableMatches = t.GetMatches(MatchesOption::FocusableOnly);
cout << "" << endl;
cout << "--- Focusable Matches Only (" << focusableMatches.Count() << ") ---" << endl;
cout << focusableMatches.Text() << endl;
}
--- All Matches (3) ---
ID:100
Name:Admin
ID:200
--- Focusable Matches Only (2) ---
ID:100
ID:200 #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; uCalc::Transformer t; t.Text("ID:100, Name:Admin, ID:200"); // Define two rules, but only one is marked as 'focusable' t.Pattern("ID:{@Number}").SetFocusable(true); t.Pattern("Name:{@Alpha}").SetFocusable(false); t.Find(); // Get all matches using the default option auto allMatches = t.GetMatches(); cout << "--- All Matches (" << allMatches.Count() << ") ---" << endl; cout << allMatches.Text() << endl; // Get only the focusable matches auto focusableMatches = t.GetMatches(MatchesOption::FocusableOnly); cout << "" << endl; cout << "--- Focusable Matches Only (" << focusableMatches.Count() << ") ---" << endl; cout << focusableMatches.Text() << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
Dim t As New uCalc.Transformer()
t.Text = "ID:100, Name:Admin, ID:200"
'// Define two rules, but only one is marked as 'focusable'
t.Pattern("ID:{@Number}").SetFocusable(true)
t.Pattern("Name:{@Alpha}").SetFocusable(false)
t.Find()
'// Get all matches using the default option
Dim allMatches = t.GetMatches()
Console.WriteLine($"--- All Matches ({allMatches.Count()}) ---")
Console.WriteLine(allMatches.Text)
'// Get only the focusable matches
Dim focusableMatches = t.GetMatches(MatchesOption.FocusableOnly)
Console.WriteLine("")
Console.WriteLine($"--- Focusable Matches Only ({focusableMatches.Count()}) ---")
Console.WriteLine(focusableMatches.Text)
End Sub
End Module
--- All Matches (3) ---
ID:100
Name:Admin
ID:200
--- Focusable Matches Only (2) ---
ID:100
ID:200 Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() Dim t As New uCalc.Transformer() t.Text = "ID:100, Name:Admin, ID:200" '// Define two rules, but only one is marked as 'focusable' t.Pattern("ID:{@Number}").SetFocusable(true) t.Pattern("Name:{@Alpha}").SetFocusable(false) t.Find() '// Get all matches using the default option Dim allMatches = t.GetMatches() Console.WriteLine($"--- All Matches ({allMatches.Count()}) ---") Console.WriteLine(allMatches.Text) '// Get only the focusable matches Dim focusableMatches = t.GetMatches(MatchesOption.FocusableOnly) Console.WriteLine("") Console.WriteLine($"--- Focusable Matches Only ({focusableMatches.Count()}) ---") Console.WriteLine(focusableMatches.Text) End Sub End Module
Parses a log file and uses the `FocusableOnly` option to quickly extract only the critical error entries.
using uCalcSoftware;
var uc = new uCalc();
var t = new uCalc.Transformer();
var log = "INFO: Task started. ERROR: Connection failed. INFO: Task finished.";
t.Text = log;
// Rules for different log levels. Only errors are focusable.
t.Pattern("INFO: {msg}.").SetFocusable(false);
t.Pattern("ERROR: {msg}.").SetFocusable(true);
t.Find();
Console.WriteLine("All log entries:");
Console.WriteLine(t.GetMatches().Text);
Console.WriteLine("");
Console.WriteLine("Critical errors only:");
// Use the option to filter for only the important entries
var errorMatches = t.GetMatches(MatchesOption.FocusableOnly);
Console.WriteLine(errorMatches.Text);
All log entries:
INFO: Task started.
ERROR: Connection failed.
INFO: Task finished.
Critical errors only:
ERROR: Connection failed. using uCalcSoftware; var uc = new uCalc(); var t = new uCalc.Transformer(); var log = "INFO: Task started. ERROR: Connection failed. INFO: Task finished."; t.Text = log; // Rules for different log levels. Only errors are focusable. t.Pattern("INFO: {msg}.").SetFocusable(false); t.Pattern("ERROR: {msg}.").SetFocusable(true); t.Find(); Console.WriteLine("All log entries:"); Console.WriteLine(t.GetMatches().Text); Console.WriteLine(""); Console.WriteLine("Critical errors only:"); // Use the option to filter for only the important entries var errorMatches = t.GetMatches(MatchesOption.FocusableOnly); Console.WriteLine(errorMatches.Text);
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
uCalc::Transformer t;
auto log = "INFO: Task started. ERROR: Connection failed. INFO: Task finished.";
t.Text(log);
// Rules for different log levels. Only errors are focusable.
t.Pattern("INFO: {msg}.").SetFocusable(false);
t.Pattern("ERROR: {msg}.").SetFocusable(true);
t.Find();
cout << "All log entries:" << endl;
cout << t.GetMatches().Text() << endl;
cout << "" << endl;
cout << "Critical errors only:" << endl;
// Use the option to filter for only the important entries
auto errorMatches = t.GetMatches(MatchesOption::FocusableOnly);
cout << errorMatches.Text() << endl;
}
All log entries:
INFO: Task started.
ERROR: Connection failed.
INFO: Task finished.
Critical errors only:
ERROR: Connection failed. #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; uCalc::Transformer t; auto log = "INFO: Task started. ERROR: Connection failed. INFO: Task finished."; t.Text(log); // Rules for different log levels. Only errors are focusable. t.Pattern("INFO: {msg}.").SetFocusable(false); t.Pattern("ERROR: {msg}.").SetFocusable(true); t.Find(); cout << "All log entries:" << endl; cout << t.GetMatches().Text() << endl; cout << "" << endl; cout << "Critical errors only:" << endl; // Use the option to filter for only the important entries auto errorMatches = t.GetMatches(MatchesOption::FocusableOnly); cout << errorMatches.Text() << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
Dim t As New uCalc.Transformer()
Dim log = "INFO: Task started. ERROR: Connection failed. INFO: Task finished."
t.Text = log
'// Rules for different log levels. Only errors are focusable.
t.Pattern("INFO: {msg}.").SetFocusable(false)
t.Pattern("ERROR: {msg}.").SetFocusable(true)
t.Find()
Console.WriteLine("All log entries:")
Console.WriteLine(t.GetMatches().Text)
Console.WriteLine("")
Console.WriteLine("Critical errors only:")
'// Use the option to filter for only the important entries
Dim errorMatches = t.GetMatches(MatchesOption.FocusableOnly)
Console.WriteLine(errorMatches.Text)
End Sub
End Module
All log entries:
INFO: Task started.
ERROR: Connection failed.
INFO: Task finished.
Critical errors only:
ERROR: Connection failed. Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() Dim t As New uCalc.Transformer() Dim log = "INFO: Task started. ERROR: Connection failed. INFO: Task finished." t.Text = log '// Rules for different log levels. Only errors are focusable. t.Pattern("INFO: {msg}.").SetFocusable(false) t.Pattern("ERROR: {msg}.").SetFocusable(true) t.Find() Console.WriteLine("All log entries:") Console.WriteLine(t.GetMatches().Text) Console.WriteLine("") Console.WriteLine("Critical errors only:") '// Use the option to filter for only the important entries Dim errorMatches = t.GetMatches(MatchesOption.FocusableOnly) Console.WriteLine(errorMatches.Text) End Sub End Module
Returns Start and End positions of Transformer matches
using uCalcSoftware;
var uc = new uCalc();
var t = uc.NewTransformer();
t.Text = "
First
Blah Blah
Testing
Second
";
// ^ ^ ^ ^
// 012345678901234567890123456789012345678901234567890123456789
// 0 10 20 30 40 50
// Carrets (^) point to Start and End locations of the matches
Console.WriteLine(t.Text);
Console.WriteLine("");
t.Pattern("<{tag}>{etc}{tag}>");
t.Find();
var Matches = t.Matches;
Console.WriteLine(Matches[0].Text);
Console.WriteLine($"Start pos: {Matches[0].StartPosition}");
Console.WriteLine($"End pos: {Matches[0].EndPosition}");
Console.WriteLine($"Length: {Matches[0].Length}");
Console.WriteLine("");
Console.WriteLine(Matches[1].Text);
Console.WriteLine($"Start pos: {Matches[1].StartPosition}");
Console.WriteLine($"End pos: {Matches[1].EndPosition}");
Console.WriteLine($"Length: {Matches[1].Length}");
<br><h1>First</h1>Blah Blah<br>Testing<br><h2>Second</h2>
<h1>First</h1>
Start pos: 4
End pos: 18
Length: 14
<h2>Second</h2>
Start pos: 42
End pos: 57
Length: 15 using uCalcSoftware; var uc = new uCalc(); var t = uc.NewTransformer(); t.Text = "<br><h1>First</h1>Blah Blah<br>Testing<br><h2>Second</h2>"; // ^ ^ ^ ^ // 012345678901234567890123456789012345678901234567890123456789 // 0 10 20 30 40 50 // Carrets (^) point to Start and End locations of the matches Console.WriteLine(t.Text); Console.WriteLine(""); t.Pattern("<{tag}>{etc}</{tag}>"); t.Find(); var Matches = t.Matches; Console.WriteLine(Matches[0].Text); Console.WriteLine($"Start pos: {Matches[0].StartPosition}"); Console.WriteLine($"End pos: {Matches[0].EndPosition}"); Console.WriteLine($"Length: {Matches[0].Length}"); Console.WriteLine(""); Console.WriteLine(Matches[1].Text); Console.WriteLine($"Start pos: {Matches[1].StartPosition}"); Console.WriteLine($"End pos: {Matches[1].EndPosition}"); Console.WriteLine($"Length: {Matches[1].Length}");
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
auto t = uc.NewTransformer();
t.Text("
First
Blah Blah
Testing
Second
");
// ^ ^ ^ ^
// 012345678901234567890123456789012345678901234567890123456789
// 0 10 20 30 40 50
// Carrets (^) point to Start and End locations of the matches
cout << t.Text() << endl;
cout << "" << endl;
t.Pattern("<{tag}>{etc}{tag}>");
t.Find();
auto Matches = t.Matches();
cout << Matches[0].Text() << endl;
cout << "Start pos: " << Matches[0].StartPosition() << endl;
cout << "End pos: " << Matches[0].EndPosition() << endl;
cout << "Length: " << Matches[0].Length() << endl;
cout << "" << endl;
cout << Matches[1].Text() << endl;
cout << "Start pos: " << Matches[1].StartPosition() << endl;
cout << "End pos: " << Matches[1].EndPosition() << endl;
cout << "Length: " << Matches[1].Length() << endl;
}
<br><h1>First</h1>Blah Blah<br>Testing<br><h2>Second</h2>
<h1>First</h1>
Start pos: 4
End pos: 18
Length: 14
<h2>Second</h2>
Start pos: 42
End pos: 57
Length: 15 #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; auto t = uc.NewTransformer(); t.Text("<br><h1>First</h1>Blah Blah<br>Testing<br><h2>Second</h2>"); // ^ ^ ^ ^ // 012345678901234567890123456789012345678901234567890123456789 // 0 10 20 30 40 50 // Carrets (^) point to Start and End locations of the matches cout << t.Text() << endl; cout << "" << endl; t.Pattern("<{tag}>{etc}</{tag}>"); t.Find(); auto Matches = t.Matches(); cout << Matches[0].Text() << endl; cout << "Start pos: " << Matches[0].StartPosition() << endl; cout << "End pos: " << Matches[0].EndPosition() << endl; cout << "Length: " << Matches[0].Length() << endl; cout << "" << endl; cout << Matches[1].Text() << endl; cout << "Start pos: " << Matches[1].StartPosition() << endl; cout << "End pos: " << Matches[1].EndPosition() << endl; cout << "Length: " << Matches[1].Length() << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
Dim t = uc.NewTransformer()
t.Text = "
First
Blah Blah
Testing
Second
"
'// ^ ^ ^ ^
'// 012345678901234567890123456789012345678901234567890123456789
'// 0 10 20 30 40 50
'// Carrets (^) point to Start and End locations of the matches
Console.WriteLine(t.Text)
Console.WriteLine("")
t.Pattern("<{tag}>{etc}{tag}>")
t.Find()
Dim Matches = t.Matches
Console.WriteLine(Matches(0).Text)
Console.WriteLine($"Start pos: {Matches(0).StartPosition}")
Console.WriteLine($"End pos: {Matches(0).EndPosition}")
Console.WriteLine($"Length: {Matches(0).Length}")
Console.WriteLine("")
Console.WriteLine(Matches(1).Text)
Console.WriteLine($"Start pos: {Matches(1).StartPosition}")
Console.WriteLine($"End pos: {Matches(1).EndPosition}")
Console.WriteLine($"Length: {Matches(1).Length}")
End Sub
End Module
<br><h1>First</h1>Blah Blah<br>Testing<br><h2>Second</h2>
<h1>First</h1>
Start pos: 4
End pos: 18
Length: 14
<h2>Second</h2>
Start pos: 42
End pos: 57
Length: 15 Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() Dim t = uc.NewTransformer() t.Text = "<br><h1>First</h1>Blah Blah<br>Testing<br><h2>Second</h2>" '// ^ ^ ^ ^ '// 012345678901234567890123456789012345678901234567890123456789 '// 0 10 20 30 40 50 '// Carrets (^) point to Start and End locations of the matches Console.WriteLine(t.Text) Console.WriteLine("") t.Pattern("<{tag}>{etc}</{tag}>") t.Find() Dim Matches = t.Matches Console.WriteLine(Matches(0).Text) Console.WriteLine($"Start pos: {Matches(0).StartPosition}") Console.WriteLine($"End pos: {Matches(0).EndPosition}") Console.WriteLine($"Length: {Matches(0).Length}") Console.WriteLine("") Console.WriteLine(Matches(1).Text) Console.WriteLine($"Start pos: {Matches(1).StartPosition}") Console.WriteLine($"End pos: {Matches(1).EndPosition}") Console.WriteLine($"Length: {Matches(1).Length}") End Sub End Module
Matches
using uCalcSoftware;
var uc = new uCalc();
var t = uc.NewTransformer();
t.Text = "Title
Bold statementOther textMy paragraph
";
// 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456
// 0 10 20 30 40 50 60 70 80 90
// ^ ^ ^ ^ ^
// Carrets (^) represent starting and ending point of the matches
t.Pattern("<{tag}>{text}{tag}>");
t.Pattern("{text}");
t.Pattern("{text}
");
t.SkipOver("");
t.Find();
foreach(var match in t.Matches) {
Console.WriteLine(match.Text);
Console.WriteLine($"Start pos: {match.StartPosition}");
Console.WriteLine($"End pos: {match.EndPosition}");
Console.WriteLine($"Length: {match.Length}");
Console.WriteLine("");
}
<h3>Title</h3>
Start pos: 0
End pos: 14
Length: 14
<b>Bold statement</b>
Start pos: 14
End pos: 35
Length: 21
<b>Other text</b>
Start pos: 58
End pos: 75
Length: 17
<p>My paragraph</p>
Start pos: 75
End pos: 94
Length: 19 using uCalcSoftware; var uc = new uCalc(); var t = uc.NewTransformer(); t.Text = "<h3>Title</h3><b>Bold statement</b><!--<h3>Title B</h3>--><b>Other text</b><p>My paragraph</p>"; // 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456 // 0 10 20 30 40 50 60 70 80 90 // ^ ^ ^ ^ ^ // Carrets (^) represent starting and ending point of the matches t.Pattern("<{tag}>{text}</{tag}>"); t.Pattern("<b>{text}</b>"); t.Pattern("<h3>{text}</h3>"); t.SkipOver("<!--{text}-->"); t.Find(); foreach(var match in t.Matches) { Console.WriteLine(match.Text); Console.WriteLine($"Start pos: {match.StartPosition}"); Console.WriteLine($"End pos: {match.EndPosition}"); Console.WriteLine($"Length: {match.Length}"); Console.WriteLine(""); }
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
auto t = uc.NewTransformer();
t.Text("Title
Bold statementOther textMy paragraph
");
// 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456
// 0 10 20 30 40 50 60 70 80 90
// ^ ^ ^ ^ ^
// Carrets (^) represent starting and ending point of the matches
t.Pattern("<{tag}>{text}{tag}>");
t.Pattern("{text}");
t.Pattern("{text}
");
t.SkipOver("");
t.Find();
for(auto match : t.Matches()) {
cout << match.Text() << endl;
cout << "Start pos: " << match.StartPosition() << endl;
cout << "End pos: " << match.EndPosition() << endl;
cout << "Length: " << match.Length() << endl;
cout << "" << endl;
}
}
<h3>Title</h3>
Start pos: 0
End pos: 14
Length: 14
<b>Bold statement</b>
Start pos: 14
End pos: 35
Length: 21
<b>Other text</b>
Start pos: 58
End pos: 75
Length: 17
<p>My paragraph</p>
Start pos: 75
End pos: 94
Length: 19 #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; auto t = uc.NewTransformer(); t.Text("<h3>Title</h3><b>Bold statement</b><!--<h3>Title B</h3>--><b>Other text</b><p>My paragraph</p>"); // 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456 // 0 10 20 30 40 50 60 70 80 90 // ^ ^ ^ ^ ^ // Carrets (^) represent starting and ending point of the matches t.Pattern("<{tag}>{text}</{tag}>"); t.Pattern("<b>{text}</b>"); t.Pattern("<h3>{text}</h3>"); t.SkipOver("<!--{text}-->"); t.Find(); for(auto match : t.Matches()) { cout << match.Text() << endl; cout << "Start pos: " << match.StartPosition() << endl; cout << "End pos: " << match.EndPosition() << endl; cout << "Length: " << match.Length() << endl; cout << "" << endl; } }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
Dim t = uc.NewTransformer()
t.Text = "Title
Bold statementOther textMy paragraph
"
'// 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456
'// 0 10 20 30 40 50 60 70 80 90
'// ^ ^ ^ ^ ^
'// Carrets (^) represent starting and ending point of the matches
t.Pattern("<{tag}>{text}{tag}>")
t.Pattern("{text}")
t.Pattern("{text}
")
t.SkipOver("")
t.Find()
For Each match In t.Matches
Console.WriteLine(match.Text)
Console.WriteLine($"Start pos: {match.StartPosition}")
Console.WriteLine($"End pos: {match.EndPosition}")
Console.WriteLine($"Length: {match.Length}")
Console.WriteLine("")
Next
End Sub
End Module
<h3>Title</h3>
Start pos: 0
End pos: 14
Length: 14
<b>Bold statement</b>
Start pos: 14
End pos: 35
Length: 21
<b>Other text</b>
Start pos: 58
End pos: 75
Length: 17
<p>My paragraph</p>
Start pos: 75
End pos: 94
Length: 19 Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() Dim t = uc.NewTransformer() t.Text = "<h3>Title</h3><b>Bold statement</b><!--<h3>Title B</h3>--><b>Other text</b><p>My paragraph</p>" '// 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456 '// 0 10 20 30 40 50 60 70 80 90 '// ^ ^ ^ ^ ^ '// Carrets (^) represent starting and ending point of the matches t.Pattern("<{tag}>{text}</{tag}>") t.Pattern("<b>{text}</b>") t.Pattern("<h3>{text}</h3>") t.SkipOver("<!--{text}-->") t.Find() For Each match In t.Matches Console.WriteLine(match.Text) Console.WriteLine($"Start pos: {match.StartPosition}") Console.WriteLine($"End pos: {match.EndPosition}") Console.WriteLine($"Length: {match.Length}") Console.WriteLine("") Next End Sub End Module
Filters matches by rule; FilterByRule, Matches.Str, Matches.Count
using uCalcSoftware;
var uc = new uCalc();
var t = uc.NewTransformer();
t.Str("Title
Bold statementTitle B
Other textMy paragraph
");
var AnyOtherTag = t.Pattern("<{tag}>{text}{tag}>");
var BoldTag = t.Pattern("{text}");
var H3Tag = t.Pattern("{text}
");
t.Find();
Console.WriteLine($"All matches -- count = {t.Matches.Count()}");
Console.WriteLine("----------------------");
Console.WriteLine(t.Matches);
Console.WriteLine("");
Console.WriteLine($"Only BoldTag matches -- count = {BoldTag.Matches.Count()}");
Console.WriteLine("-------------------------------");
Console.WriteLine(BoldTag.Matches);
Console.WriteLine("");
Console.WriteLine($"Only H3Tag matches -- count = {H3Tag.Matches.Count()}");
Console.WriteLine("-----------------------------");
Console.WriteLine(H3Tag.Matches);
All matches -- count = 5
----------------------
<h3>Title</h3>
<b>Bold statement</b>
<h3>Title B</h3>
<b>Other text</b>
<p>My paragraph</p>
Only BoldTag matches -- count = 2
-------------------------------
<b>Bold statement</b>
<b>Other text</b>
Only H3Tag matches -- count = 2
-----------------------------
<h3>Title</h3>
<h3>Title B</h3> using uCalcSoftware; var uc = new uCalc(); var t = uc.NewTransformer(); t.Str("<h3>Title</h3><b>Bold statement</b><h3>Title B</h3><b>Other text</b><p>My paragraph</p>"); var AnyOtherTag = t.Pattern("<{tag}>{text}</{tag}>"); var BoldTag = t.Pattern("<b>{text}</b>"); var H3Tag = t.Pattern("<h3>{text}</h3>"); t.Find(); Console.WriteLine($"All matches -- count = {t.Matches.Count()}"); Console.WriteLine("----------------------"); Console.WriteLine(t.Matches); Console.WriteLine(""); Console.WriteLine($"Only BoldTag matches -- count = {BoldTag.Matches.Count()}"); Console.WriteLine("-------------------------------"); Console.WriteLine(BoldTag.Matches); Console.WriteLine(""); Console.WriteLine($"Only H3Tag matches -- count = {H3Tag.Matches.Count()}"); Console.WriteLine("-----------------------------"); Console.WriteLine(H3Tag.Matches);
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
auto t = uc.NewTransformer();
t.Str("Title
Bold statementTitle B
Other textMy paragraph
");
auto AnyOtherTag = t.Pattern("<{tag}>{text}{tag}>");
auto BoldTag = t.Pattern("{text}");
auto H3Tag = t.Pattern("{text}
");
t.Find();
cout << "All matches -- count = " << t.Matches().Count() << endl;
cout << "----------------------" << endl;
cout << t.Matches() << endl;
cout << "" << endl;
cout << "Only BoldTag matches -- count = " << BoldTag.Matches().Count() << endl;
cout << "-------------------------------" << endl;
cout << BoldTag.Matches() << endl;
cout << "" << endl;
cout << "Only H3Tag matches -- count = " << H3Tag.Matches().Count() << endl;
cout << "-----------------------------" << endl;
cout << H3Tag.Matches() << endl;
}
All matches -- count = 5
----------------------
<h3>Title</h3>
<b>Bold statement</b>
<h3>Title B</h3>
<b>Other text</b>
<p>My paragraph</p>
Only BoldTag matches -- count = 2
-------------------------------
<b>Bold statement</b>
<b>Other text</b>
Only H3Tag matches -- count = 2
-----------------------------
<h3>Title</h3>
<h3>Title B</h3> #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; auto t = uc.NewTransformer(); t.Str("<h3>Title</h3><b>Bold statement</b><h3>Title B</h3><b>Other text</b><p>My paragraph</p>"); auto AnyOtherTag = t.Pattern("<{tag}>{text}</{tag}>"); auto BoldTag = t.Pattern("<b>{text}</b>"); auto H3Tag = t.Pattern("<h3>{text}</h3>"); t.Find(); cout << "All matches -- count = " << t.Matches().Count() << endl; cout << "----------------------" << endl; cout << t.Matches() << endl; cout << "" << endl; cout << "Only BoldTag matches -- count = " << BoldTag.Matches().Count() << endl; cout << "-------------------------------" << endl; cout << BoldTag.Matches() << endl; cout << "" << endl; cout << "Only H3Tag matches -- count = " << H3Tag.Matches().Count() << endl; cout << "-----------------------------" << endl; cout << H3Tag.Matches() << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
Dim t = uc.NewTransformer()
t.Str("Title
Bold statementTitle B
Other textMy paragraph
")
Dim AnyOtherTag = t.Pattern("<{tag}>{text}{tag}>")
Dim BoldTag = t.Pattern("{text}")
Dim H3Tag = t.Pattern("{text}
")
t.Find()
Console.WriteLine($"All matches -- count = {t.Matches.Count()}")
Console.WriteLine("----------------------")
Console.WriteLine(t.Matches)
Console.WriteLine("")
Console.WriteLine($"Only BoldTag matches -- count = {BoldTag.Matches.Count()}")
Console.WriteLine("-------------------------------")
Console.WriteLine(BoldTag.Matches)
Console.WriteLine("")
Console.WriteLine($"Only H3Tag matches -- count = {H3Tag.Matches.Count()}")
Console.WriteLine("-----------------------------")
Console.WriteLine(H3Tag.Matches)
End Sub
End Module
All matches -- count = 5
----------------------
<h3>Title</h3>
<b>Bold statement</b>
<h3>Title B</h3>
<b>Other text</b>
<p>My paragraph</p>
Only BoldTag matches -- count = 2
-------------------------------
<b>Bold statement</b>
<b>Other text</b>
Only H3Tag matches -- count = 2
-----------------------------
<h3>Title</h3>
<h3>Title B</h3> Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() Dim t = uc.NewTransformer() t.Str("<h3>Title</h3><b>Bold statement</b><h3>Title B</h3><b>Other text</b><p>My paragraph</p>") Dim AnyOtherTag = t.Pattern("<{tag}>{text}</{tag}>") Dim BoldTag = t.Pattern("<b>{text}</b>") Dim H3Tag = t.Pattern("<h3>{text}</h3>") t.Find() Console.WriteLine($"All matches -- count = {t.Matches.Count()}") Console.WriteLine("----------------------") Console.WriteLine(t.Matches) Console.WriteLine("") Console.WriteLine($"Only BoldTag matches -- count = {BoldTag.Matches.Count()}") Console.WriteLine("-------------------------------") Console.WriteLine(BoldTag.Matches) Console.WriteLine("") Console.WriteLine($"Only H3Tag matches -- count = {H3Tag.Matches.Count()}") Console.WriteLine("-----------------------------") Console.WriteLine(H3Tag.Matches) End Sub End Module
Focusable to toggle pattern matches
using uCalcSoftware;
var uc = new uCalc();
var t = uc.NewTransformer();
t.Str("Title
Bold statementTitle B
Other text");
var BoldTag = t.Pattern("{text}").SetFocusable(true);
var H3Tag = t.Pattern("{text}
").SetFocusable(true);
t.Find();
Console.WriteLine(t.GetMatches(MatchesOption.FocusableOnly).Text);
Console.WriteLine("");
BoldTag.Focusable = false;
Console.WriteLine($"BoldTag.Focusable(): {BoldTag.Focusable}");
Console.WriteLine("--------------------------");
// t.Find(); // A Find operation does not have to be executed again
Console.WriteLine(t.GetMatches(MatchesOption.FocusableOnly).Text);
Console.WriteLine("");
BoldTag.Focusable = true;
Console.WriteLine($"BoldTag.Focusable(): {BoldTag.Focusable}");
Console.WriteLine("--------------------------");
//t.Find(); // A Find operation does not have to be executed again
Console.WriteLine(t.GetMatches(MatchesOption.FocusableOnly).Text);
Console.WriteLine("");
<h3>Title</h3>
<b>Bold statement</b>
<h3>Title B</h3>
<b>Other text</b>
BoldTag.Focusable(): False
--------------------------
<h3>Title</h3>
<h3>Title B</h3>
BoldTag.Focusable(): True
--------------------------
<h3>Title</h3>
<b>Bold statement</b>
<h3>Title B</h3>
<b>Other text</b> using uCalcSoftware; var uc = new uCalc(); var t = uc.NewTransformer(); t.Str("<h3>Title</h3><b>Bold statement</b><h3>Title B</h3><b>Other text</b>"); var BoldTag = t.Pattern("<b>{text}</b>").SetFocusable(true); var H3Tag = t.Pattern("<h3>{text}</h3>").SetFocusable(true); t.Find(); Console.WriteLine(t.GetMatches(MatchesOption.FocusableOnly).Text); Console.WriteLine(""); BoldTag.Focusable = false; Console.WriteLine($"BoldTag.Focusable(): {BoldTag.Focusable}"); Console.WriteLine("--------------------------"); // t.Find(); // A Find operation does not have to be executed again Console.WriteLine(t.GetMatches(MatchesOption.FocusableOnly).Text); Console.WriteLine(""); BoldTag.Focusable = true; Console.WriteLine($"BoldTag.Focusable(): {BoldTag.Focusable}"); Console.WriteLine("--------------------------"); //t.Find(); // A Find operation does not have to be executed again Console.WriteLine(t.GetMatches(MatchesOption.FocusableOnly).Text); Console.WriteLine("");
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
#define tf(IsTrue) ((IsTrue) ? "True" : "False")
int main() {
uCalc uc;
auto t = uc.NewTransformer();
t.Str("Title
Bold statementTitle B
Other text");
auto BoldTag = t.Pattern("{text}").SetFocusable(true);
auto H3Tag = t.Pattern("{text}
").SetFocusable(true);
t.Find();
cout << t.GetMatches(MatchesOption::FocusableOnly).Text() << endl;
cout << "" << endl;
BoldTag.Focusable(false);
cout << "BoldTag.Focusable(): " << tf(BoldTag.Focusable()) << endl;
cout << "--------------------------" << endl;
// t.Find(); // A Find operation does not have to be executed again
cout << t.GetMatches(MatchesOption::FocusableOnly).Text() << endl;
cout << "" << endl;
BoldTag.Focusable(true);
cout << "BoldTag.Focusable(): " << tf(BoldTag.Focusable()) << endl;
cout << "--------------------------" << endl;
//t.Find(); // A Find operation does not have to be executed again
cout << t.GetMatches(MatchesOption::FocusableOnly).Text() << endl;
cout << "" << endl;
}
<h3>Title</h3>
<b>Bold statement</b>
<h3>Title B</h3>
<b>Other text</b>
BoldTag.Focusable(): False
--------------------------
<h3>Title</h3>
<h3>Title B</h3>
BoldTag.Focusable(): True
--------------------------
<h3>Title</h3>
<b>Bold statement</b>
<h3>Title B</h3>
<b>Other text</b> #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; #define tf(IsTrue) ((IsTrue) ? "True" : "False") int main() { uCalc uc; auto t = uc.NewTransformer(); t.Str("<h3>Title</h3><b>Bold statement</b><h3>Title B</h3><b>Other text</b>"); auto BoldTag = t.Pattern("<b>{text}</b>").SetFocusable(true); auto H3Tag = t.Pattern("<h3>{text}</h3>").SetFocusable(true); t.Find(); cout << t.GetMatches(MatchesOption::FocusableOnly).Text() << endl; cout << "" << endl; BoldTag.Focusable(false); cout << "BoldTag.Focusable(): " << tf(BoldTag.Focusable()) << endl; cout << "--------------------------" << endl; // t.Find(); // A Find operation does not have to be executed again cout << t.GetMatches(MatchesOption::FocusableOnly).Text() << endl; cout << "" << endl; BoldTag.Focusable(true); cout << "BoldTag.Focusable(): " << tf(BoldTag.Focusable()) << endl; cout << "--------------------------" << endl; //t.Find(); // A Find operation does not have to be executed again cout << t.GetMatches(MatchesOption::FocusableOnly).Text() << endl; cout << "" << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
Dim t = uc.NewTransformer()
t.Str("Title
Bold statementTitle B
Other text")
Dim BoldTag = t.Pattern("{text}").SetFocusable(true)
Dim H3Tag = t.Pattern("{text}
").SetFocusable(true)
t.Find()
Console.WriteLine(t.GetMatches(MatchesOption.FocusableOnly).Text)
Console.WriteLine("")
BoldTag.Focusable = false
Console.WriteLine($"BoldTag.Focusable(): {BoldTag.Focusable}")
Console.WriteLine("--------------------------")
'// t.Find(); // A Find operation does not have to be executed again
Console.WriteLine(t.GetMatches(MatchesOption.FocusableOnly).Text)
Console.WriteLine("")
BoldTag.Focusable = true
Console.WriteLine($"BoldTag.Focusable(): {BoldTag.Focusable}")
Console.WriteLine("--------------------------")
'//t.Find(); // A Find operation does not have to be executed again
Console.WriteLine(t.GetMatches(MatchesOption.FocusableOnly).Text)
Console.WriteLine("")
End Sub
End Module
<h3>Title</h3>
<b>Bold statement</b>
<h3>Title B</h3>
<b>Other text</b>
BoldTag.Focusable(): False
--------------------------
<h3>Title</h3>
<h3>Title B</h3>
BoldTag.Focusable(): True
--------------------------
<h3>Title</h3>
<b>Bold statement</b>
<h3>Title B</h3>
<b>Other text</b> Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() Dim t = uc.NewTransformer() t.Str("<h3>Title</h3><b>Bold statement</b><h3>Title B</h3><b>Other text</b>") Dim BoldTag = t.Pattern("<b>{text}</b>").SetFocusable(true) Dim H3Tag = t.Pattern("<h3>{text}</h3>").SetFocusable(true) t.Find() Console.WriteLine(t.GetMatches(MatchesOption.FocusableOnly).Text) Console.WriteLine("") BoldTag.Focusable = false Console.WriteLine($"BoldTag.Focusable(): {BoldTag.Focusable}") Console.WriteLine("--------------------------") '// t.Find(); // A Find operation does not have to be executed again Console.WriteLine(t.GetMatches(MatchesOption.FocusableOnly).Text) Console.WriteLine("") BoldTag.Focusable = true Console.WriteLine($"BoldTag.Focusable(): {BoldTag.Focusable}") Console.WriteLine("--------------------------") '//t.Find(); // A Find operation does not have to be executed again Console.WriteLine(t.GetMatches(MatchesOption.FocusableOnly).Text) Console.WriteLine("") End Sub End Module
Focusable to select only patterns from local transformer
using uCalcSoftware;
var uc = new uCalc();
var t = uc.NewTransformer();
var FruitsXML =
"""
""";
// List names of fruit within comment, not the whole comment as well
t.Text = FruitsXML;
var CommentedFruits = t.Pattern("").SetFocusable(false);
var CommentedFruitsTr = CommentedFruits.LocalTransformer;
CommentedFruitsTr.FromTo("CommonName={@string:text}", "{text}").Focusable = true;
t.Filter();
Console.WriteLine("With Focusable()");
Console.WriteLine("----------------");
Console.WriteLine(t.GetMatches(MatchesOption.FocusableOnly).Text);
Console.WriteLine("");
// Note: The displayed Fruit element is modified by CommentedFruitsTr.FromTo()
Console.WriteLine("Without Focusable()");
Console.WriteLine("-------------------");
Console.WriteLine(t.Matches.Text);
With Focusable()
----------------
Grapes
Mango
Rambutan
Watermelon
Without Focusable()
-------------------
<!-- <Fruit Grapes ScientificName='Vitis vinifera' /> -->
Grapes
<!-- <Fruit Mango ScientificName='Mangifera indica' /> -->
Mango
<!-- <Fruit Rambutan ScientificName='Nephelium lappaceum' /> -->
Rambutan
<!-- <Fruit Watermelon ScientificName='Citrullus lanatus' /> -->
Watermelon using uCalcSoftware; var uc = new uCalc(); var t = uc.NewTransformer(); var FruitsXML = """ <Fruits> <Fruit CommonName='Apple' ScientificName='Malus domestica' /> <Fruit CommonName='Banana' ScientificName='Musa acuminata' /> <Fruit CommonName='Orange' ScientificName='Citrus × sinensis' /> <!-- <Fruit CommonName='Grapes' ScientificName='Vitis vinifera' /> --> <Fruit CommonName='Strawberry' ScientificName='Fragaria × ananassa' /> <Fruit CommonName='Pineapple' ScientificName='Ananas comosus' /> <!-- <Fruit CommonName='Mango' ScientificName='Mangifera indica' /> --> <Fruit CommonName='Blueberry' ScientificName='Vaccinium corymbosum' /> <!-- <Fruit CommonName='Rambutan' ScientificName='Nephelium lappaceum' /> --> <Fruit CommonName='Salak (Snake Fruit)' ScientificName='Salacca zalacca' /> <Fruit CommonName='Jabuticaba' ScientificName='Plinia cauliflora' /> <!-- <Fruit CommonName='Watermelon' ScientificName='Citrullus lanatus' /> --> </Fruits> """; // List names of fruit within comment, not the whole comment as well t.Text = FruitsXML; var CommentedFruits = t.Pattern("<!-- {comment} -->").SetFocusable(false); var CommentedFruitsTr = CommentedFruits.LocalTransformer; CommentedFruitsTr.FromTo("CommonName={@string:text}", "{text}").Focusable = true; t.Filter(); Console.WriteLine("With Focusable()"); Console.WriteLine("----------------"); Console.WriteLine(t.GetMatches(MatchesOption.FocusableOnly).Text); Console.WriteLine(""); // Note: The displayed Fruit element is modified by CommentedFruitsTr.FromTo() Console.WriteLine("Without Focusable()"); Console.WriteLine("-------------------"); Console.WriteLine(t.Matches.Text);
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
auto t = uc.NewTransformer();
auto FruitsXML =
R"(
)";
// List names of fruit within comment, not the whole comment as well
t.Text(FruitsXML);
auto CommentedFruits = t.Pattern("").SetFocusable(false);
auto CommentedFruitsTr = CommentedFruits.LocalTransformer();
CommentedFruitsTr.FromTo("CommonName={@string:text}", "{text}").Focusable(true);
t.Filter();
cout << "With Focusable()" << endl;
cout << "----------------" << endl;
cout << t.GetMatches(MatchesOption::FocusableOnly).Text() << endl;
cout << "" << endl;
// Note: The displayed Fruit element is modified by CommentedFruitsTr.FromTo()
cout << "Without Focusable()" << endl;
cout << "-------------------" << endl;
cout << t.Matches().Text() << endl;
}
With Focusable()
----------------
Grapes
Mango
Rambutan
Watermelon
Without Focusable()
-------------------
<!-- <Fruit Grapes ScientificName='Vitis vinifera' /> -->
Grapes
<!-- <Fruit Mango ScientificName='Mangifera indica' /> -->
Mango
<!-- <Fruit Rambutan ScientificName='Nephelium lappaceum' /> -->
Rambutan
<!-- <Fruit Watermelon ScientificName='Citrullus lanatus' /> -->
Watermelon #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; auto t = uc.NewTransformer(); auto FruitsXML = R"( <Fruits> <Fruit CommonName='Apple' ScientificName='Malus domestica' /> <Fruit CommonName='Banana' ScientificName='Musa acuminata' /> <Fruit CommonName='Orange' ScientificName='Citrus × sinensis' /> <!-- <Fruit CommonName='Grapes' ScientificName='Vitis vinifera' /> --> <Fruit CommonName='Strawberry' ScientificName='Fragaria × ananassa' /> <Fruit CommonName='Pineapple' ScientificName='Ananas comosus' /> <!-- <Fruit CommonName='Mango' ScientificName='Mangifera indica' /> --> <Fruit CommonName='Blueberry' ScientificName='Vaccinium corymbosum' /> <!-- <Fruit CommonName='Rambutan' ScientificName='Nephelium lappaceum' /> --> <Fruit CommonName='Salak (Snake Fruit)' ScientificName='Salacca zalacca' /> <Fruit CommonName='Jabuticaba' ScientificName='Plinia cauliflora' /> <!-- <Fruit CommonName='Watermelon' ScientificName='Citrullus lanatus' /> --> </Fruits> )"; // List names of fruit within comment, not the whole comment as well t.Text(FruitsXML); auto CommentedFruits = t.Pattern("<!-- {comment} -->").SetFocusable(false); auto CommentedFruitsTr = CommentedFruits.LocalTransformer(); CommentedFruitsTr.FromTo("CommonName={@string:text}", "{text}").Focusable(true); t.Filter(); cout << "With Focusable()" << endl; cout << "----------------" << endl; cout << t.GetMatches(MatchesOption::FocusableOnly).Text() << endl; cout << "" << endl; // Note: The displayed Fruit element is modified by CommentedFruitsTr.FromTo() cout << "Without Focusable()" << endl; cout << "-------------------" << endl; cout << t.Matches().Text() << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
Dim t = uc.NewTransformer()
Dim FruitsXML =
"
"
'// List names of fruit within comment, not the whole comment as well
t.Text = FruitsXML
Dim CommentedFruits = t.Pattern("").SetFocusable(false)
Dim CommentedFruitsTr = CommentedFruits.LocalTransformer
CommentedFruitsTr.FromTo("CommonName={@string:text}", "{text}").Focusable = true
t.Filter()
Console.WriteLine("With Focusable()")
Console.WriteLine("----------------")
Console.WriteLine(t.GetMatches(MatchesOption.FocusableOnly).Text)
Console.WriteLine("")
'// Note: The displayed Fruit element is modified by CommentedFruitsTr.FromTo()
Console.WriteLine("Without Focusable()")
Console.WriteLine("-------------------")
Console.WriteLine(t.Matches.Text)
End Sub
End Module
With Focusable()
----------------
Grapes
Mango
Rambutan
Watermelon
Without Focusable()
-------------------
<!-- <Fruit Grapes ScientificName='Vitis vinifera' /> -->
Grapes
<!-- <Fruit Mango ScientificName='Mangifera indica' /> -->
Mango
<!-- <Fruit Rambutan ScientificName='Nephelium lappaceum' /> -->
Rambutan
<!-- <Fruit Watermelon ScientificName='Citrullus lanatus' /> -->
Watermelon Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() Dim t = uc.NewTransformer() Dim FruitsXML = " <Fruits> <Fruit CommonName='Apple' ScientificName='Malus domestica' /> <Fruit CommonName='Banana' ScientificName='Musa acuminata' /> <Fruit CommonName='Orange' ScientificName='Citrus × sinensis' /> <!-- <Fruit CommonName='Grapes' ScientificName='Vitis vinifera' /> --> <Fruit CommonName='Strawberry' ScientificName='Fragaria × ananassa' /> <Fruit CommonName='Pineapple' ScientificName='Ananas comosus' /> <!-- <Fruit CommonName='Mango' ScientificName='Mangifera indica' /> --> <Fruit CommonName='Blueberry' ScientificName='Vaccinium corymbosum' /> <!-- <Fruit CommonName='Rambutan' ScientificName='Nephelium lappaceum' /> --> <Fruit CommonName='Salak (Snake Fruit)' ScientificName='Salacca zalacca' /> <Fruit CommonName='Jabuticaba' ScientificName='Plinia cauliflora' /> <!-- <Fruit CommonName='Watermelon' ScientificName='Citrullus lanatus' /> --> </Fruits> " '// List names of fruit within comment, not the whole comment as well t.Text = FruitsXML Dim CommentedFruits = t.Pattern("<!-- {comment} -->").SetFocusable(false) Dim CommentedFruitsTr = CommentedFruits.LocalTransformer CommentedFruitsTr.FromTo("CommonName={@string:text}", "{text}").Focusable = true t.Filter() Console.WriteLine("With Focusable()") Console.WriteLine("----------------") Console.WriteLine(t.GetMatches(MatchesOption.FocusableOnly).Text) Console.WriteLine("") '// Note: The displayed Fruit element is modified by CommentedFruitsTr.FromTo() Console.WriteLine("Without Focusable()") Console.WriteLine("-------------------") Console.WriteLine(t.Matches.Text) End Sub End Module
MatchesOption: RootLevelOnly and InnermostOnly
using uCalcSoftware;
var uc = new uCalc();
var t = uc.NewTransformer();
var txt = "xyz
Hello
World
";
t.Str(txt);
t.Pattern("").LocalTransformer.FromTo("id={@string:id}", "{id}");
t.Filter();
Console.WriteLine("All matches");
Console.WriteLine("-----------");
Console.WriteLine(t.GetMatches(MatchesOption.All).Text); // All is the default
Console.WriteLine("");
Console.WriteLine("RootLevelOnly");
Console.WriteLine("-------------");
Console.WriteLine(t.GetMatches(MatchesOption.RootLevelOnly).Text);
Console.WriteLine("");
Console.WriteLine("InnermostOnly");
Console.WriteLine("-------------");
Console.WriteLine(t.GetMatches(MatchesOption.InnermostOnly).Text);
Console.WriteLine("");
All matches
-----------
<p aa>
aa
<p bb>
bb
<p cc>
cc
RootLevelOnly
-------------
<p aa>
<p bb>
<p cc>
InnermostOnly
-------------
aa
bb
cc using uCalcSoftware; var uc = new uCalc(); var t = uc.NewTransformer(); var txt = "<p id='aa'>xyz</p><p id='bb'>Hello</p ><p id='cc'>World</p>"; t.Str(txt); t.Pattern("<p {etc}>").LocalTransformer.FromTo("id={@string:id}", "{id}"); t.Filter(); Console.WriteLine("All matches"); Console.WriteLine("-----------"); Console.WriteLine(t.GetMatches(MatchesOption.All).Text); // All is the default Console.WriteLine(""); Console.WriteLine("RootLevelOnly"); Console.WriteLine("-------------"); Console.WriteLine(t.GetMatches(MatchesOption.RootLevelOnly).Text); Console.WriteLine(""); Console.WriteLine("InnermostOnly"); Console.WriteLine("-------------"); Console.WriteLine(t.GetMatches(MatchesOption.InnermostOnly).Text); Console.WriteLine("");
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
auto t = uc.NewTransformer();
auto txt = "xyz
Hello
World
";
t.Str(txt);
t.Pattern("").LocalTransformer().FromTo("id={@string:id}", "{id}");
t.Filter();
cout << "All matches" << endl;
cout << "-----------" << endl;
cout << t.GetMatches(MatchesOption::All).Text() << endl; // All is the default
cout << "" << endl;
cout << "RootLevelOnly" << endl;
cout << "-------------" << endl;
cout << t.GetMatches(MatchesOption::RootLevelOnly).Text() << endl;
cout << "" << endl;
cout << "InnermostOnly" << endl;
cout << "-------------" << endl;
cout << t.GetMatches(MatchesOption::InnermostOnly).Text() << endl;
cout << "" << endl;
}
All matches
-----------
<p aa>
aa
<p bb>
bb
<p cc>
cc
RootLevelOnly
-------------
<p aa>
<p bb>
<p cc>
InnermostOnly
-------------
aa
bb
cc #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; auto t = uc.NewTransformer(); auto txt = "<p id='aa'>xyz</p><p id='bb'>Hello</p ><p id='cc'>World</p>"; t.Str(txt); t.Pattern("<p {etc}>").LocalTransformer().FromTo("id={@string:id}", "{id}"); t.Filter(); cout << "All matches" << endl; cout << "-----------" << endl; cout << t.GetMatches(MatchesOption::All).Text() << endl; // All is the default cout << "" << endl; cout << "RootLevelOnly" << endl; cout << "-------------" << endl; cout << t.GetMatches(MatchesOption::RootLevelOnly).Text() << endl; cout << "" << endl; cout << "InnermostOnly" << endl; cout << "-------------" << endl; cout << t.GetMatches(MatchesOption::InnermostOnly).Text() << endl; cout << "" << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
Dim t = uc.NewTransformer()
Dim txt = "xyz
Hello
World
"
t.Str(txt)
t.Pattern("").LocalTransformer.FromTo("id={@string:id}", "{id}")
t.Filter()
Console.WriteLine("All matches")
Console.WriteLine("-----------")
Console.WriteLine(t.GetMatches(MatchesOption.All).Text) '// All is the default
Console.WriteLine("")
Console.WriteLine("RootLevelOnly")
Console.WriteLine("-------------")
Console.WriteLine(t.GetMatches(MatchesOption.RootLevelOnly).Text)
Console.WriteLine("")
Console.WriteLine("InnermostOnly")
Console.WriteLine("-------------")
Console.WriteLine(t.GetMatches(MatchesOption.InnermostOnly).Text)
Console.WriteLine("")
End Sub
End Module
All matches
-----------
<p aa>
aa
<p bb>
bb
<p cc>
cc
RootLevelOnly
-------------
<p aa>
<p bb>
<p cc>
InnermostOnly
-------------
aa
bb
cc Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() Dim t = uc.NewTransformer() Dim txt = "<p id='aa'>xyz</p><p id='bb'>Hello</p ><p id='cc'>World</p>" t.Str(txt) t.Pattern("<p {etc}>").LocalTransformer.FromTo("id={@string:id}", "{id}") t.Filter() Console.WriteLine("All matches") Console.WriteLine("-----------") Console.WriteLine(t.GetMatches(MatchesOption.All).Text) '// All is the default Console.WriteLine("") Console.WriteLine("RootLevelOnly") Console.WriteLine("-------------") Console.WriteLine(t.GetMatches(MatchesOption.RootLevelOnly).Text) Console.WriteLine("") Console.WriteLine("InnermostOnly") Console.WriteLine("-------------") Console.WriteLine(t.GetMatches(MatchesOption.InnermostOnly).Text) Console.WriteLine("") End Sub End Module