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.

Pattern = [string]

Property

Product: 

Transformer Library

Class: 

Rule

Retrieves or sets the pattern string that defines a rule's matching criteria.

Remarks

The Pattern property provides runtime access to the "source code" of a Rule's pattern definition. This allows for powerful introspection into the logic of a Transformer at runtime.

This property applies to rules created with both the Pattern() and FromTo() methods, returning the pattern string from either.

⚙️ Getter and Setter Behavior

  • Getter: When called without arguments, myRule.@Pattern() retrieves the original string that defines the rule's matching logic.
  • Setter: When called with a string argument, myRule.@Pattern("new pattern") is intended to modify the rule's pattern at runtime. Note: This functionality is not yet fully implemented and may not have any effect.

🎯 Core Use Cases

  • Debugging: When iterating through a collection of Matches, you can retrieve the Rule for each Match and then use this property to log the exact pattern that generated it. This is invaluable for understanding why a particular piece of text was matched.
  • Dynamic UI and Tooling: Build IDE-like features, such as a property inspector that can display the pattern for a selected rule.
  • Metaprogramming: Analyze the structure of one rule's pattern to dynamically generate or modify another.

💡 Comparative Analysis

In compiled languages like C# or C++, reflection can provide metadata about a method—such as its name and parameters—but it cannot retrieve the original source code. Rule.Pattern is fundamentally different because the uCalc engine retains the complete definition string.

This capability bridges the gap between a compiled, executable rule and its human-readable source, making uCalc an exceptionally powerful tool for dynamic and interactive applications.

Examples

A succinct example showing how to retrieve the pattern string from a defined rule.
				
					using uCalcSoftware;

var uc = new uCalc();
var t = uc.NewTransformer();
var rule = t.FromTo("Hello {name}", "Greetings, {name}!");

Console.WriteLine($"Rule pattern is: '{rule.Pattern}'");
				
			
Rule pattern is: 'Hello {name}'
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   auto t = uc.NewTransformer();
   auto rule = t.FromTo("Hello {name}", "Greetings, {name}!");

   cout << "Rule pattern is: '" << rule.Pattern() << "'" << endl;
}
				
			
Rule pattern is: 'Hello {name}'
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      Dim t = uc.NewTransformer()
      Dim rule = t.FromTo("Hello {name}", "Greetings, {name}!")
      
      Console.WriteLine($"Rule pattern is: '{rule.Pattern}'")
   End Sub
End Module
				
			
Rule pattern is: 'Hello {name}'
A practical debugging example that identifies which pattern string generated each match.
				
					using uCalcSoftware;

var uc = new uCalc();
var t = uc.NewTransformer();
t.Text = "An apple and a car.";

// Define two separate rules
t.FromTo("apple", "[FRUIT]");
t.FromTo("car", "[VEHICLE]");

t.Find();

var matches = t.Matches;
Console.WriteLine($"Found {matches.Count()} matches:");
foreach(var match in matches) {
   var rule = match.Rule;
   Console.WriteLine($"- Matched '{match.Text}' using pattern: '{rule.Pattern}'");
}
				
			
Found 2 matches:
- Matched 'apple' using pattern: 'apple'
- Matched 'car' using pattern: 'car'
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   auto t = uc.NewTransformer();
   t.Text("An apple and a car.");

   // Define two separate rules
   t.FromTo("apple", "[FRUIT]");
   t.FromTo("car", "[VEHICLE]");

   t.Find();

   auto matches = t.Matches();
   cout << "Found " << matches.Count() << " matches:" << endl;
   for(auto match : matches) {
      auto rule = match.Rule();
      cout << "- Matched '" << match.Text() << "' using pattern: '" << rule.Pattern() << "'" << endl;
   }
}
				
			
Found 2 matches:
- Matched 'apple' using pattern: 'apple'
- Matched 'car' using pattern: 'car'
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      Dim t = uc.NewTransformer()
      t.Text = "An apple and a car."
      
      '// Define two separate rules
      t.FromTo("apple", "[FRUIT]")
      t.FromTo("car", "[VEHICLE]")
      
      t.Find()
      
      Dim matches = t.Matches
      Console.WriteLine($"Found {matches.Count()} matches:")
      For Each match In matches
         Dim rule = match.Rule
         Console.WriteLine($"- Matched '{match.Text}' using pattern: '{rule.Pattern}'")
      Next
   End Sub
End Module
				
			
Found 2 matches:
- Matched 'apple' using pattern: 'apple'
- Matched 'car' using pattern: 'car'
Internal Test: Verifies that the correct pattern string is returned for rules created with both FromTo() and Pattern(), including complex syntax.
				
					using uCalcSoftware;

var uc = new uCalc();
var t = uc.NewTransformer();

// Rule created with FromTo
var rule1 = t.FromTo("Key: {@Number:val}", "{val}");

// Rule created with Pattern
var rule2 = t.Pattern("<{tag}>{content}</{tag}>");

Console.WriteLine($"Rule 1 Pattern: {rule1.Pattern}");
Console.WriteLine($"Rule 2 Pattern: {rule2.Pattern}");
				
			
Rule 1 Pattern: Key: {@Number:val}
Rule 2 Pattern: <{tag}>{content}</{tag}>
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   auto t = uc.NewTransformer();

   // Rule created with FromTo
   auto rule1 = t.FromTo("Key: {@Number:val}", "{val}");

   // Rule created with Pattern
   auto rule2 = t.Pattern("<{tag}>{content}</{tag}>");

   cout << "Rule 1 Pattern: " << rule1.Pattern() << endl;
   cout << "Rule 2 Pattern: " << rule2.Pattern() << endl;
}
				
			
Rule 1 Pattern: Key: {@Number:val}
Rule 2 Pattern: <{tag}>{content}</{tag}>
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      Dim t = uc.NewTransformer()
      
      '// Rule created with FromTo
      Dim rule1 = t.FromTo("Key: {@Number:val}", "{val}")
      
      '// Rule created with Pattern
      Dim rule2 = t.Pattern("<{tag}>{content}</{tag}>")
      
      Console.WriteLine($"Rule 1 Pattern: {rule1.Pattern}")
      Console.WriteLine($"Rule 2 Pattern: {rule2.Pattern}")
   End Sub
End Module
				
			
Rule 1 Pattern: Key: {@Number:val}
Rule 2 Pattern: <{tag}>{content}</{tag}>
Rule Name
				
					using uCalcSoftware;

var uc = new uCalc();
var t = uc.NewTransformer();
t.Text = "<b>(5+4)</b> this and that etc";
var a = t.Pattern("<{tg}>");
var b = t.Pattern("This {body} That");
var c = t.Pattern("etc");
var d = t.Pattern("({expr})");

t.Filter();
Console.WriteLine("--- Matches ---");
Console.WriteLine(t.Matches.Text);
Console.WriteLine("--- Pattern names ---");
Console.WriteLine(a.Name);
Console.WriteLine(b.Name);
Console.WriteLine(c.Name);
Console.WriteLine(d.Name);
Console.WriteLine("--- Pattern defs ---");
Console.WriteLine(a.Pattern);
Console.WriteLine(b.Pattern);
Console.WriteLine(c.Pattern);
Console.WriteLine(d.Pattern);
				
			
--- Matches ---
<b>
(5+4)
</b>
this and that
etc
--- Pattern names ---
<
this
etc
(
--- Pattern defs ---
<{tg}>
This {body} That
etc
({expr})
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   auto t = uc.NewTransformer();
   t.Text("<b>(5+4)</b> this and that etc");
   auto a = t.Pattern("<{tg}>");
   auto b = t.Pattern("This {body} That");
   auto c = t.Pattern("etc");
   auto d = t.Pattern("({expr})");

   t.Filter();
   cout << "--- Matches ---" << endl;
   cout << t.Matches().Text() << endl;
   cout << "--- Pattern names ---" << endl;
   cout << a.Name() << endl;
   cout << b.Name() << endl;
   cout << c.Name() << endl;
   cout << d.Name() << endl;
   cout << "--- Pattern defs ---" << endl;
   cout << a.Pattern() << endl;
   cout << b.Pattern() << endl;
   cout << c.Pattern() << endl;
   cout << d.Pattern() << endl;
}
				
			
--- Matches ---
<b>
(5+4)
</b>
this and that
etc
--- Pattern names ---
<
this
etc
(
--- Pattern defs ---
<{tg}>
This {body} That
etc
({expr})
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      Dim t = uc.NewTransformer()
      t.Text = "<b>(5+4)</b> this and that etc"
      Dim a = t.Pattern("<{tg}>")
      Dim b = t.Pattern("This {body} That")
      Dim c = t.Pattern("etc")
      Dim d = t.Pattern("({expr})")
      
      t.Filter()
      Console.WriteLine("--- Matches ---")
      Console.WriteLine(t.Matches.Text)
      Console.WriteLine("--- Pattern names ---")
      Console.WriteLine(a.Name)
      Console.WriteLine(b.Name)
      Console.WriteLine(c.Name)
      Console.WriteLine(d.Name)
      Console.WriteLine("--- Pattern defs ---")
      Console.WriteLine(a.Pattern)
      Console.WriteLine(b.Pattern)
      Console.WriteLine(c.Pattern)
      Console.WriteLine(d.Pattern)
   End Sub
End Module
				
			
--- Matches ---
<b>
(5+4)
</b>
this and that
etc
--- Pattern names ---
<
this
etc
(
--- Pattern defs ---
<{tg}>
This {body} That
etc
({expr})
Rule NextOverload and Tag
				
					using uCalcSoftware;

var uc = new uCalc();
var t = uc.NewTransformer();
t.Text = "Testing (a b c) Testing x y z! Testing 1 2 3.";

var Pattern1 = t.Pattern("Testing {etc}.").SetTag(111);
var Pattern2 = t.Pattern("Testing {etc}!").SetTag(222);
var Pattern3 = t.Pattern("Testing ({etc})").SetTag(333);

t.Find();
Console.WriteLine("--- Matches ---");
Console.WriteLine(t.Matches.Text);
Console.WriteLine("--- Patterns ---");
Console.WriteLine(Pattern1.Pattern);
Console.WriteLine(Pattern2.Pattern);
Console.WriteLine(Pattern3.Pattern);
Console.WriteLine("---- Tags ----");
Console.WriteLine(Pattern1.Tag);
Console.WriteLine(Pattern2.Tag);
Console.WriteLine(Pattern3.Tag);
Console.WriteLine("-- Overload Tags --");
// Note that most recently defined patterns come first
Console.WriteLine(Pattern3.NextOverload().Tag);
Console.WriteLine(Pattern2.NextOverload().Tag);
Console.WriteLine(Pattern1.NextOverload().Tag);


				
			
--- Matches ---
Testing (a b c)
Testing x y z!
Testing 1 2 3.
--- Patterns ---
Testing {etc}.
Testing {etc}!
Testing ({etc})
---- Tags ----
111
222
333
-- Overload Tags --
222
111
0
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   auto t = uc.NewTransformer();
   t.Text("Testing (a b c) Testing x y z! Testing 1 2 3.");

   auto Pattern1 = t.Pattern("Testing {etc}.").SetTag(111);
   auto Pattern2 = t.Pattern("Testing {etc}!").SetTag(222);
   auto Pattern3 = t.Pattern("Testing ({etc})").SetTag(333);

   t.Find();
   cout << "--- Matches ---" << endl;
   cout << t.Matches().Text() << endl;
   cout << "--- Patterns ---" << endl;
   cout << Pattern1.Pattern() << endl;
   cout << Pattern2.Pattern() << endl;
   cout << Pattern3.Pattern() << endl;
   cout << "---- Tags ----" << endl;
   cout << Pattern1.Tag() << endl;
   cout << Pattern2.Tag() << endl;
   cout << Pattern3.Tag() << endl;
   cout << "-- Overload Tags --" << endl;
   // Note that most recently defined patterns come first
   cout << Pattern3.NextOverload().Tag() << endl;
   cout << Pattern2.NextOverload().Tag() << endl;
   cout << Pattern1.NextOverload().Tag() << endl;


}
				
			
--- Matches ---
Testing (a b c)
Testing x y z!
Testing 1 2 3.
--- Patterns ---
Testing {etc}.
Testing {etc}!
Testing ({etc})
---- Tags ----
111
222
333
-- Overload Tags --
222
111
0
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      Dim t = uc.NewTransformer()
      t.Text = "Testing (a b c) Testing x y z! Testing 1 2 3."
      
      Dim Pattern1 = t.Pattern("Testing {etc}.").SetTag(111)
      Dim Pattern2 = t.Pattern("Testing {etc}!").SetTag(222)
      Dim Pattern3 = t.Pattern("Testing ({etc})").SetTag(333)
      
      t.Find()
      Console.WriteLine("--- Matches ---")
      Console.WriteLine(t.Matches.Text)
      Console.WriteLine("--- Patterns ---")
      Console.WriteLine(Pattern1.Pattern)
      Console.WriteLine(Pattern2.Pattern)
      Console.WriteLine(Pattern3.Pattern)
      Console.WriteLine("---- Tags ----")
      Console.WriteLine(Pattern1.Tag)
      Console.WriteLine(Pattern2.Tag)
      Console.WriteLine(Pattern3.Tag)
      Console.WriteLine("-- Overload Tags --")
      '// Note that most recently defined patterns come first
      Console.WriteLine(Pattern3.NextOverload().Tag)
      Console.WriteLine(Pattern2.NextOverload().Tag)
      Console.WriteLine(Pattern1.NextOverload().Tag)
      
      
   End Sub
End Module
				
			
--- Matches ---
Testing (a b c)
Testing x y z!
Testing 1 2 3.
--- Patterns ---
Testing {etc}.
Testing {etc}!
Testing ({etc})
---- Tags ----
111
222
333
-- Overload Tags --
222
111
0