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.
Count
Method
Product:
Class:
Gets the total number of matches found by a Transformer operation.
Syntax
Parameters
Return
int
The total number of matches found in the collection.
Remarks
Count() returns the total number of matches found by the most recent Transformer operation, such as Find(), Filter(), or Transform().
🎯 Primary Use Case: Loop Boundaries
This method is most commonly used to determine the upper bound for a for loop that iterates through the collection of matches to inspect or process each one individually.
// Get the collection of all matchesvar allMatches = myTransformer.Matches();// Loop from the first match to the lastfor ( i = 0; i <= allMatches.Count() - 1; i++) { // Access the i-th match Console.WriteLine($"Match {i}: {allMatches[i].Text}");}🌍 Global Count vs. Rule-Specific Count
It's important to distinguish between the total match count and the count for a specific rule:
myTransformer.Matches().Count(): Returns the total number of matches found by all active rules in the transformer.myRule.Matches().Count(): Returns the number of matches found only by that specific rule.
This allows for both a high-level overview and a granular analysis of the transformation results.
💡 Comparative Analysis
The Count() method is analogous to .Count properties on collections in C# or .size() methods in C++. It provides a familiar way to determine the size of a result set.
However, unlike a simple collection, the Matches object represents the outcome of a complex, pattern-based search across an input string. Its count reflects how many times the defined rules successfully matched segments of the text, taking into account precedence, tokenization, and any exclusion rules (like SkipOver). The value is therefore the result of a dynamic process, not just the size of a static list.
Examples
A succinct example demonstrating how to count all alphanumeric words in a sentence.
using uCalcSoftware;
var uc = new uCalc();
var t = uc.NewTransformer();
t.Text = "There are five words here.";
// Define a pattern to find any alphanumeric word
t.Pattern("{@Alpha}");
t.Find();
Console.WriteLine($"Total words found: {t.Matches.Count()}");
Total words found: 5 using uCalcSoftware; var uc = new uCalc(); var t = uc.NewTransformer(); t.Text = "There are five words here."; // Define a pattern to find any alphanumeric word t.Pattern("{@Alpha}"); t.Find(); Console.WriteLine($"Total words found: {t.Matches.Count()}");
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
auto t = uc.NewTransformer();
t.Text("There are five words here.");
// Define a pattern to find any alphanumeric word
t.Pattern("{@Alpha}");
t.Find();
cout << "Total words found: " << t.Matches().Count() << endl;
}
Total words found: 5 #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; auto t = uc.NewTransformer(); t.Text("There are five words here."); // Define a pattern to find any alphanumeric word t.Pattern("{@Alpha}"); t.Find(); cout << "Total words found: " << t.Matches().Count() << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
Dim t = uc.NewTransformer()
t.Text = "There are five words here."
'// Define a pattern to find any alphanumeric word
t.Pattern("{@Alpha}")
t.Find()
Console.WriteLine($"Total words found: {t.Matches.Count()}")
End Sub
End Module
Total words found: 5 Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() Dim t = uc.NewTransformer() t.Text = "There are five words here." '// Define a pattern to find any alphanumeric word t.Pattern("{@Alpha}") t.Find() Console.WriteLine($"Total words found: {t.Matches.Count()}") End Sub End Module
A practical example showing the difference between counting all matches and counting matches for a specific rule.
using uCalcSoftware;
var uc = new uCalc();
var t = uc.NewTransformer();
t.Str("Header
Paragraph 1.
Paragraph 2.
");
// Define rules for different tags
var h1Rule = t.Pattern("{text}
");
var pRule = t.Pattern("{text}
");
t.Find();
// Get the total count of all matches from all rules
Console.WriteLine($"Total matches (all rules): {t.Matches.Count()}");
// Get the count for only the paragraph rule
Console.WriteLine($"Paragraph matches only: {pRule.Matches.Count()}");
Total matches (all rules): 3
Paragraph matches only: 2 using uCalcSoftware; var uc = new uCalc(); var t = uc.NewTransformer(); t.Str("<h1>Header</h1><p>Paragraph 1.</p><p>Paragraph 2.</p>"); // Define rules for different tags var h1Rule = t.Pattern("<h1>{text}</h1>"); var pRule = t.Pattern("<p>{text}</p>"); t.Find(); // Get the total count of all matches from all rules Console.WriteLine($"Total matches (all rules): {t.Matches.Count()}"); // Get the count for only the paragraph rule Console.WriteLine($"Paragraph matches only: {pRule.Matches.Count()}");
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
auto t = uc.NewTransformer();
t.Str("Header
Paragraph 1.
Paragraph 2.
");
// Define rules for different tags
auto h1Rule = t.Pattern("{text}
");
auto pRule = t.Pattern("{text}
");
t.Find();
// Get the total count of all matches from all rules
cout << "Total matches (all rules): " << t.Matches().Count() << endl;
// Get the count for only the paragraph rule
cout << "Paragraph matches only: " << pRule.Matches().Count() << endl;
}
Total matches (all rules): 3
Paragraph matches only: 2 #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; auto t = uc.NewTransformer(); t.Str("<h1>Header</h1><p>Paragraph 1.</p><p>Paragraph 2.</p>"); // Define rules for different tags auto h1Rule = t.Pattern("<h1>{text}</h1>"); auto pRule = t.Pattern("<p>{text}</p>"); t.Find(); // Get the total count of all matches from all rules cout << "Total matches (all rules): " << t.Matches().Count() << endl; // Get the count for only the paragraph rule cout << "Paragraph matches only: " << pRule.Matches().Count() << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
Dim t = uc.NewTransformer()
t.Str("Header
Paragraph 1.
Paragraph 2.
")
'// Define rules for different tags
Dim h1Rule = t.Pattern("{text}
")
Dim pRule = t.Pattern("{text}
")
t.Find()
'// Get the total count of all matches from all rules
Console.WriteLine($"Total matches (all rules): {t.Matches.Count()}")
'// Get the count for only the paragraph rule
Console.WriteLine($"Paragraph matches only: {pRule.Matches.Count()}")
End Sub
End Module
Total matches (all rules): 3
Paragraph matches only: 2 Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() Dim t = uc.NewTransformer() t.Str("<h1>Header</h1><p>Paragraph 1.</p><p>Paragraph 2.</p>") '// Define rules for different tags Dim h1Rule = t.Pattern("<h1>{text}</h1>") Dim pRule = t.Pattern("<p>{text}</p>") t.Find() '// Get the total count of all matches from all rules Console.WriteLine($"Total matches (all rules): {t.Matches.Count()}") '// Get the count for only the paragraph rule Console.WriteLine($"Paragraph matches only: {pRule.Matches.Count()}") End Sub End Module
Internal Test: Verifies how filtering the matches collection affects the count.
using uCalcSoftware;
var uc = new uCalc();
var t = uc.NewTransformer();
t.Text = "ID:100, Name:Admin, ID:200";
// Define two rules, but only one is marked as 'focusable'
var idRule = t.Pattern("ID:{@Number}").SetFocusable(true);
var nameRule = t.Pattern("Name:{@Alpha}").SetFocusable(false);
t.Find();
// The total count includes all matches regardless of properties
Console.WriteLine($"Total matches found: {t.Matches.Count()}");
// The count changes when we filter the list to only include focusable matches
var focusableMatches = t.GetMatches(MatchesOption.FocusableOnly);
Console.WriteLine($"Focusable matches count: {focusableMatches.Count()}");
Total matches found: 3
Focusable matches count: 2 using uCalcSoftware; var uc = new uCalc(); var t = uc.NewTransformer(); t.Text = "ID:100, Name:Admin, ID:200"; // Define two rules, but only one is marked as 'focusable' var idRule = t.Pattern("ID:{@Number}").SetFocusable(true); var nameRule = t.Pattern("Name:{@Alpha}").SetFocusable(false); t.Find(); // The total count includes all matches regardless of properties Console.WriteLine($"Total matches found: {t.Matches.Count()}"); // The count changes when we filter the list to only include focusable matches var focusableMatches = t.GetMatches(MatchesOption.FocusableOnly); Console.WriteLine($"Focusable matches count: {focusableMatches.Count()}");
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
auto t = uc.NewTransformer();
t.Text("ID:100, Name:Admin, ID:200");
// Define two rules, but only one is marked as 'focusable'
auto idRule = t.Pattern("ID:{@Number}").SetFocusable(true);
auto nameRule = t.Pattern("Name:{@Alpha}").SetFocusable(false);
t.Find();
// The total count includes all matches regardless of properties
cout << "Total matches found: " << t.Matches().Count() << endl;
// The count changes when we filter the list to only include focusable matches
auto focusableMatches = t.GetMatches(MatchesOption::FocusableOnly);
cout << "Focusable matches count: " << focusableMatches.Count() << endl;
}
Total matches found: 3
Focusable matches count: 2 #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; auto t = uc.NewTransformer(); t.Text("ID:100, Name:Admin, ID:200"); // Define two rules, but only one is marked as 'focusable' auto idRule = t.Pattern("ID:{@Number}").SetFocusable(true); auto nameRule = t.Pattern("Name:{@Alpha}").SetFocusable(false); t.Find(); // The total count includes all matches regardless of properties cout << "Total matches found: " << t.Matches().Count() << endl; // The count changes when we filter the list to only include focusable matches auto focusableMatches = t.GetMatches(MatchesOption::FocusableOnly); cout << "Focusable matches count: " << focusableMatches.Count() << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
Dim t = uc.NewTransformer()
t.Text = "ID:100, Name:Admin, ID:200"
'// Define two rules, but only one is marked as 'focusable'
Dim idRule = t.Pattern("ID:{@Number}").SetFocusable(true)
Dim nameRule = t.Pattern("Name:{@Alpha}").SetFocusable(false)
t.Find()
'// The total count includes all matches regardless of properties
Console.WriteLine($"Total matches found: {t.Matches.Count()}")
'// The count changes when we filter the list to only include focusable matches
Dim focusableMatches = t.GetMatches(MatchesOption.FocusableOnly)
Console.WriteLine($"Focusable matches count: {focusableMatches.Count()}")
End Sub
End Module
Total matches found: 3
Focusable matches count: 2 Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() Dim t = uc.NewTransformer() t.Text = "ID:100, Name:Admin, ID:200" '// Define two rules, but only one is marked as 'focusable' Dim idRule = t.Pattern("ID:{@Number}").SetFocusable(true) Dim nameRule = t.Pattern("Name:{@Alpha}").SetFocusable(false) t.Find() '// The total count includes all matches regardless of properties Console.WriteLine($"Total matches found: {t.Matches.Count()}") '// The count changes when we filter the list to only include focusable matches Dim focusableMatches = t.GetMatches(MatchesOption.FocusableOnly) Console.WriteLine($"Focusable matches count: {focusableMatches.Count()}") End Sub End Module
How to find matched patterns while skipping commented text using SkipOver().
using uCalcSoftware;
var uc = new uCalc();
var t = uc.NewTransformer();
t.Str("int result = (x + 3) * 2 - (y - 7 / z) * (5 ^ a + 10); /* (x + y) */");
// Capture standard blocks surrounded by parentheses
t.Pattern("({expr})");
// Instruct the transformer to ignore any text inside C-style block comments.
// This prevents the commented "(x + y)" from being falsely counted as a match.
t.SkipOver("/* {etc} */"); // commented text between /* */ is skipped
t.Find();
Console.WriteLine(t.Matches.Count());
3 using uCalcSoftware; var uc = new uCalc(); var t = uc.NewTransformer(); t.Str("int result = (x + 3) * 2 - (y - 7 / z) * (5 ^ a + 10); /* (x + y) */"); // Capture standard blocks surrounded by parentheses t.Pattern("({expr})"); // Instruct the transformer to ignore any text inside C-style block comments. // This prevents the commented "(x + y)" from being falsely counted as a match. t.SkipOver("/* {etc} */"); // commented text between /* */ is skipped t.Find(); Console.WriteLine(t.Matches.Count());
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
auto t = uc.NewTransformer();
t.Str("int result = (x + 3) * 2 - (y - 7 / z) * (5 ^ a + 10); /* (x + y) */");
// Capture standard blocks surrounded by parentheses
t.Pattern("({expr})");
// Instruct the transformer to ignore any text inside C-style block comments.
// This prevents the commented "(x + y)" from being falsely counted as a match.
t.SkipOver("/* {etc} */"); // commented text between /* */ is skipped
t.Find();
cout << t.Matches().Count() << endl;
}
3 #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; auto t = uc.NewTransformer(); t.Str("int result = (x + 3) * 2 - (y - 7 / z) * (5 ^ a + 10); /* (x + y) */"); // Capture standard blocks surrounded by parentheses t.Pattern("({expr})"); // Instruct the transformer to ignore any text inside C-style block comments. // This prevents the commented "(x + y)" from being falsely counted as a match. t.SkipOver("/* {etc} */"); // commented text between /* */ is skipped t.Find(); cout << t.Matches().Count() << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
Dim t = uc.NewTransformer()
t.Str("int result = (x + 3) * 2 - (y - 7 / z) * (5 ^ a + 10); /* (x + y) */")
'// Capture standard blocks surrounded by parentheses
t.Pattern("({expr})")
'// Instruct the transformer to ignore any text inside C-style block comments.
'// This prevents the commented "(x + y)" from being falsely counted as a match.
t.SkipOver("/* {etc} */") '// commented text between /* */ is skipped
t.Find()
Console.WriteLine(t.Matches.Count())
End Sub
End Module
3 Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() Dim t = uc.NewTransformer() t.Str("int result = (x + 3) * 2 - (y - 7 / z) * (5 ^ a + 10); /* (x + y) */") '// Capture standard blocks surrounded by parentheses t.Pattern("({expr})") '// Instruct the transformer to ignore any text inside C-style block comments. '// This prevents the commented "(x + y)" from being falsely counted as a match. t.SkipOver("/* {etc} */") '// commented text between /* */ is skipped t.Find() Console.WriteLine(t.Matches.Count()) 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