uCalc API Version: 5.7.0-preview.1 Released: 7/30/2026
Warning
uCalc API Preview Release Notice:This preview documentation describes the intended behavior of the API. It is not fully accurate or complete.The current preview build contains incomplete features, unoptimized performance, and is subject to breaking changes.Use of the preview version in your production code is not recommended.
Product:
Class:
Defines a find-only search pattern that locates text without replacing it, populating the matches collection.
Rule containing the search pattern
The Pattern method defines a rule for finding text within a Transformer without replacing it. It is the primary method for pure search-and-analysis operations where the goal is to locate text segments and inspect their properties, rather than modify the source string.
{@Self}Unlike its counterpart FromTo(), which requires an explicit replacement string, Pattern has an implicit replacement behavior. If a rule defined with Pattern is used in a Transform() operation, it automatically uses the special {@Self} keyword as its replacement. This means the matched text is simply replaced by itself, leaving the source string unchanged but still populating the Matches collection with the results of the find operation.
Pattern() vs. FromTo()Choosing the right method depends on your goal:
| Method | Purpose | Replacement Behavior | Primary Use Case |
|---|---|---|---|
Pattern(p) | Find Only | Implicitly {@Self}. Re-inserts the matched text. | Locating patterns, counting occurrences, and analyzing text without modification. |
FromTo(p, r) | Find and Replace | Explicitly defined by the r parameter. | Text transformation, data normalization, search-and-replace. |
For find-only operations, Pattern offers significant advantages over traditional regular expressions.
func(a, (b+c)). uCalc's Pattern method operates on tokens, so it inherently understands these structures, preventing incorrect matches inside string literals or across mismatched brackets.(pattern1|pattern2|...)). With uCalc, you define each pattern with a separate, clear Pattern() call, and the engine executes them all concurrently in a single pass.ID: 111
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
ID: 114
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