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:
Gets or sets the replacement string of a rule, which defines the output text for a pattern match.
The Replacement property provides runtime access to the "source code" of a rule's replacement string—the part of the rule that defines the output. It allows you to programmatically inspect or even modify what a matched text segment will be transformed into.
This property applies to rules created with both FromTo() and Pattern().
This property can be used to both read and write a rule's replacement logic:
myRule.Replacement retrieves the literal string that defines the rule's output.myRule.Replacement = "new replacement text" modifies the rule at runtime. This change affects all subsequent Transform() operations.Pattern() vs. FromTo()Understanding the default replacement behavior is crucial:
FromTo("pattern", "replacement"), this property returns the exact "replacement" string you provided.Pattern("pattern"), which have no explicit replacement, this property returns the special keyword {@Self}. This keyword instructs the transformer to re-insert the matched text without any changes, which is the default behavior for a find-only Pattern rule.A replacement string is more than just literal text. It can contain dynamic components:
{varName} inserts the text captured by a variable in the pattern.{@Eval} or {@File} can execute logic, perform calculations, or load content during the replacement phase. For more details, see Pattern Methods.Traditional regex engines typically use a simple, string-based replacement model with numeric or named backreferences.
Hi, $2 $1 to reorder captured groups. This is functional but limited.Replacement: uCalc's model is far more powerful:{lastName}, {firstName}) instead of cryptic indices.{var:text-if-found}) and can execute complex logic directly within the string using {@Eval: {var} * 1.1}, capabilities that would require a separate callback function in most other engines.ID: 134
using uCalcSoftware;
var uc = new uCalc();
var t = uc.NewTransformer();
t.Text = "aaa bbb xyz 123";
var aaa = t.FromTo("aaa", "111");
var xyz = t.Pattern("xyz");
t.Filter();
Console.WriteLine(t.Matches.Text);
Console.WriteLine("-----");
Console.WriteLine(aaa.Replacement);
Console.WriteLine(xyz.Replacement);
111
xyz
-----
111
{@Self} using uCalcSoftware; var uc = new uCalc(); var t = uc.NewTransformer(); t.Text = "aaa bbb xyz 123"; var aaa = t.FromTo("aaa", "111"); var xyz = t.Pattern("xyz"); t.Filter(); Console.WriteLine(t.Matches.Text); Console.WriteLine("-----"); Console.WriteLine(aaa.Replacement); Console.WriteLine(xyz.Replacement);
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
auto t = uc.NewTransformer();
t.Text("aaa bbb xyz 123");
auto aaa = t.FromTo("aaa", "111");
auto xyz = t.Pattern("xyz");
t.Filter();
cout << t.Matches().Text() << endl;
cout << "-----" << endl;
cout << aaa.Replacement() << endl;
cout << xyz.Replacement() << endl;
}
111
xyz
-----
111
{@Self} #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; auto t = uc.NewTransformer(); t.Text("aaa bbb xyz 123"); auto aaa = t.FromTo("aaa", "111"); auto xyz = t.Pattern("xyz"); t.Filter(); cout << t.Matches().Text() << endl; cout << "-----" << endl; cout << aaa.Replacement() << endl; cout << xyz.Replacement() << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
Dim t = uc.NewTransformer()
t.Text = "aaa bbb xyz 123"
Dim aaa = t.FromTo("aaa", "111")
Dim xyz = t.Pattern("xyz")
t.Filter()
Console.WriteLine(t.Matches.Text)
Console.WriteLine("-----")
Console.WriteLine(aaa.Replacement)
Console.WriteLine(xyz.Replacement)
End Sub
End Module
111
xyz
-----
111
{@Self} Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() Dim t = uc.NewTransformer() t.Text = "aaa bbb xyz 123" Dim aaa = t.FromTo("aaa", "111") Dim xyz = t.Pattern("xyz") t.Filter() Console.WriteLine(t.Matches.Text) Console.WriteLine("-----") Console.WriteLine(aaa.Replacement) Console.WriteLine(xyz.Replacement) End Sub End Module