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.
Defines the recognition rules -- using literals, variable types, or complex syntax -- that the parser uses to identify and process input tokens.
uCalc Patterns provide a high-level, token-based syntax for defining search criteria and text transformations. Unlike traditional string searches that match exact characters, or Regular Expressions (Regex) that rely on complex character-level syntax, uCalc patterns operate primarily on Tokens (words, numbers, symbols). This approach allows for more readable definitions that naturally respect word boundaries and structure.
A pattern string is the fundamental argument passed to methods such as Transformer.Pattern() and Transformer.FromTo(). These patterns define the criteria for Transformer.Find() and Transformer.Transform() operations.
| Syntax Element | Description | Example |
|---|---|---|
| Anchors | Literal text that must exist in the source string. | Error Code: |
| Variables | Named placeholders enclosed in curly braces. Captures variable content. | {ErrorCode} |
| Alternatives | Vertical bars inside curly braces denote "OR" logic. | { High | Medium | Low } |
| Optionals | Square brackets denote text that may or may not exist. | [Detailed] Report |
| Backreferences | Reusing a variable name enforces equality. | <{tag}>...</{tag}> |
| Token Constraints | Colon followed by a number limits the capture length. Can be named or anonymous. | {word:4} (named){4} (anonymous) captures exactly 4 tokens |
| Quoted Text | Captures an entire block of quoted text as a single unit using {@String} or {@s}. | Test {@String} matches Test 'foo' or Test "bar" |
| RegEx Embedding | Single quotes inside curly braces allow raw Regex. Can be named or anonymous. | {MyRegex:'[0-9]+'} (named){'[0-9]+'} (anonymous) |
Variable Naming & Spacing:To assign a variable name to a group, the name must immediately follow the opening curly brace without spaces.
{Type: Error | Warning} captures Error or Warning into the variable Type.{ Type: Error | Warning} matches the literal text Type: Error OR Warning. It does not create a variable named Type.Escaping Special Characters:Characters like [ and { have special meaning. To match them literally, enclose them in quotes.
['['{timestamp}']'] defines an optional section (outer brackets) containing a literal opening bracket (quoted '['), a variable, and a literal closing bracket.{@String})By default, uCalc is QuoteSensitive, meaning it treats a block of text enclosed in quotes (e.g., 'hello world' or "hello world") as a single token. The {@String} method (or shortcut {@s}) allows you to explicitly capture these blocks.
{@String} or {@s} (string and s are case-insensitive).{@s:MyText}.{MyText} or {MyText(1)}: Returns the content inside the quotes.{MyText(0)}: Returns the content including the surrounding quotes.(?<=\s)\d+(?=\s)). uCalc patterns use human-readable tokens or methods (e.g., {@Number}).\bword\b). uCalc variables like {x} automatically respect token boundaries, preventing partial matches within words.<(\w+)>.*<\/\1>) is fragile and complex. In uCalc, simply reusing the variable name <{tag}>...<{/tag}> handles the logic automatically.ID: 174
using uCalcSoftware;
var uc = new uCalc();
var t = uc.NewTransformer();
// Define the pattern first
t.FromTo("Temperature: {temp} C", "temperature: {@Eval: Double(temp) * 1.8 + 32} F");
// Perform the Transform() operation
Console.WriteLine(t.Transform("Here is the temperature: 22.5 C"));
Here is the temperature: 72.5 F using uCalcSoftware; var uc = new uCalc(); var t = uc.NewTransformer(); // Define the pattern first t.FromTo("Temperature: {temp} C", "temperature: {@Eval: Double(temp) * 1.8 + 32} F"); // Perform the Transform() operation Console.WriteLine(t.Transform("Here is the temperature: 22.5 C"));
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
auto t = uc.NewTransformer();
// Define the pattern first
t.FromTo("Temperature: {temp} C", "temperature: {@Eval: Double(temp) * 1.8 + 32} F");
// Perform the Transform() operation
cout << t.Transform("Here is the temperature: 22.5 C") << endl;
}
Here is the temperature: 72.5 F #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; auto t = uc.NewTransformer(); // Define the pattern first t.FromTo("Temperature: {temp} C", "temperature: {@Eval: Double(temp) * 1.8 + 32} F"); // Perform the Transform() operation cout << t.Transform("Here is the temperature: 22.5 C") << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
Dim t = uc.NewTransformer()
'// Define the pattern first
t.FromTo("Temperature: {temp} C", "temperature: {@Eval: Double(temp) * 1.8 + 32} F")
'// Perform the Transform() operation
Console.WriteLine(t.Transform("Here is the temperature: 22.5 C"))
End Sub
End Module
Here is the temperature: 72.5 F Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() Dim t = uc.NewTransformer() '// Define the pattern first t.FromTo("Temperature: {temp} C", "temperature: {@Eval: Double(temp) * 1.8 + 32} F") '// Perform the Transform() operation Console.WriteLine(t.Transform("Here is the temperature: 22.5 C")) End Sub End Module
ID: 199
using uCalcSoftware;
var uc = new uCalc();
var t = uc.NewTransformer();
// When a variable is used multiple times in a pattern,
// such as {tag} in this case, the matching text must be the same
t.FromTo("<{tag}> {words:2} {more} {tag}>",
"tag={tag}, 2 words={words}, text={more}");
Console.WriteLine(t.Transform("abc xyz more wordsbold").Text);
tag=div, 2 words=abc xyz, text=more words<b>bold</b> using uCalcSoftware; var uc = new uCalc(); var t = uc.NewTransformer(); // When a variable is used multiple times in a pattern, // such as {tag} in this case, the matching text must be the same t.FromTo("<{tag}> {words:2} {more} </{tag}>", "tag={tag}, 2 words={words}, text={more}"); Console.WriteLine(t.Transform("<div>abc xyz more words<b>bold</b></div>").Text);
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
auto t = uc.NewTransformer();
// When a variable is used multiple times in a pattern,
// such as {tag} in this case, the matching text must be the same
t.FromTo("<{tag}> {words:2} {more} {tag}>",
"tag={tag}, 2 words={words}, text={more}");
cout << t.Transform("abc xyz more wordsbold").Text() << endl;
}
tag=div, 2 words=abc xyz, text=more words<b>bold</b> #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; auto t = uc.NewTransformer(); // When a variable is used multiple times in a pattern, // such as {tag} in this case, the matching text must be the same t.FromTo("<{tag}> {words:2} {more} </{tag}>", "tag={tag}, 2 words={words}, text={more}"); cout << t.Transform("<div>abc xyz more words<b>bold</b></div>").Text() << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
Dim t = uc.NewTransformer()
'// When a variable is used multiple times in a pattern,
'// such as {tag} in this case, the matching text must be the same
t.FromTo("<{tag}> {words:2} {more} {tag}>",
"tag={tag}, 2 words={words}, text={more}")
Console.WriteLine(t.Transform("abc xyz more wordsbold").Text)
End Sub
End Module
tag=div, 2 words=abc xyz, text=more words<b>bold</b> Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() Dim t = uc.NewTransformer() '// When a variable is used multiple times in a pattern, '// such as {tag} in this case, the matching text must be the same t.FromTo("<{tag}> {words:2} {more} </{tag}>", "tag={tag}, 2 words={words}, text={more}") Console.WriteLine(t.Transform("<div>abc xyz more words<b>bold</b></div>").Text) End Sub End Module
ID: 197
using uCalcSoftware;
var uc = new uCalc();
var t = uc.NewTransformer();
t.FromTo("a [simple] test", "<{@Self}>");
Console.WriteLine(t.Transform("Is this a simple test, or a hard test, or just a test?"));
Is this <a simple test>, or a hard test, or just <a test>? using uCalcSoftware; var uc = new uCalc(); var t = uc.NewTransformer(); t.FromTo("a [simple] test", "<{@Self}>"); Console.WriteLine(t.Transform("Is this a simple test, or a hard test, or just a test?"));
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
auto t = uc.NewTransformer();
t.FromTo("a [simple] test", "<{@Self}>");
cout << t.Transform("Is this a simple test, or a hard test, or just a test?") << endl;
}
Is this <a simple test>, or a hard test, or just <a test>? #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; auto t = uc.NewTransformer(); t.FromTo("a [simple] test", "<{@Self}>"); cout << t.Transform("Is this a simple test, or a hard test, or just a test?") << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
Dim t = uc.NewTransformer()
t.FromTo("a [simple] test", "<{@Self}>")
Console.WriteLine(t.Transform("Is this a simple test, or a hard test, or just a test?"))
End Sub
End Module
Is this <a simple test>, or a hard test, or just <a test>? Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() Dim t = uc.NewTransformer() t.FromTo("a [simple] test", "<{@Self}>") Console.WriteLine(t.Transform("Is this a simple test, or a hard test, or just a test?")) End Sub End Module
ID: 224
using uCalcSoftware;
var uc = new uCalc();
var t = uc.NewTransformer();
// Define a rule to swap the name into a greeting
t.FromTo("Hello {name}", "Greetings, {name}!");
Console.WriteLine(t.Transform("Hello World"));
Greetings, World! using uCalcSoftware; var uc = new uCalc(); var t = uc.NewTransformer(); // Define a rule to swap the name into a greeting t.FromTo("Hello {name}", "Greetings, {name}!"); Console.WriteLine(t.Transform("Hello World"));
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
auto t = uc.NewTransformer();
// Define a rule to swap the name into a greeting
t.FromTo("Hello {name}", "Greetings, {name}!");
cout << t.Transform("Hello World") << endl;
}
Greetings, World! #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; auto t = uc.NewTransformer(); // Define a rule to swap the name into a greeting t.FromTo("Hello {name}", "Greetings, {name}!"); cout << t.Transform("Hello World") << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
Dim t = uc.NewTransformer()
'// Define a rule to swap the name into a greeting
t.FromTo("Hello {name}", "Greetings, {name}!")
Console.WriteLine(t.Transform("Hello World"))
End Sub
End Module
Greetings, World! Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() Dim t = uc.NewTransformer() '// Define a rule to swap the name into a greeting t.FromTo("Hello {name}", "Greetings, {name}!") Console.WriteLine(t.Transform("Hello World")) End Sub End Module