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.

{@Self}

Product: 

Class: 

Remarks

Description: A replacement-only keyword that represents the entire text segment captured by the pattern match.

The {@Self} keyword is used within the replacement string of a uCalc::Transformer rule. It acts as a macro for the full string of text that triggered the rule, allowing you to easily wrap or annotate existing content without manually reconstructing it using indexed parameters.

Preservation of Original Content

The primary use case for {@Self} is when you want to keep the matched text exactly as it is but add surrounding context. This is often called "wrapping."

  • Example Pattern: {@Alpha}
  • Example Replacement: [{@Self}]
  • Result: Every word in the document is wrapped in square brackets.

Comparison with Other Keywords

  • {@Self}: The total match.
  • {@Param:n}: Only a specific part of the match.
  • {@Doc}: The entire source document, regardless of the match.

Evaluation Timing

{@Self} returns the text as it was captured before the replacement logic is applied. This makes it a reliable anchor for rules that perform complex HTML tagging or document-level annotations.


Examples

1. Succinct (Quick Start: Wrapping Keywords)

Identifying a specific keyword and wrapping it in a generic tag for later processing.

New(uCalc::Transformer, t)// Match 'Warning' and add a prefix labelt.FromTo("Warning", "!!! {@Self} !!!")wl(t.Transform("Warning: System low"))

[Expected Output]!!! Warning !!!: System low

2. Practical (Real World: Automatic HTML Highlighting)

Matching a specific format (like a hex color code) and wrapping it in a span with a style attribute.

New(uCalc::Transformer, t)// Match a hex code starting with #t.FromTo("# {@Alpha:hex}", "<span style='color: {@Self}'>{@Self}</span>")wl(t.Transform("Background: #FF5500"))

[Expected Output]Background: <span style='color: #FF5500'>#FF5500</span>

3. Internal Test (Whitespace Integrity)

Verifying that {@Self} includes the literal whitespace tokens captured between pattern elements.

New(uCalc::Transformer, t)// Pattern captures: Alpha + Space + Numbert.FromTo("{@Alpha} {@Number}", "RECORD: ({@Self})")wl(t.Transform("User 123"))

[Expected Output]RECORD: (User 123)


Strategy & Critique

  • Ease of Use: {@Self} is the most frequently used replacement keyword because it handles the "heavy lifting" of re-inserting the match without requiring the developer to track parameter indices.
  • Pattern Design: When using {@Self}, be careful about what your pattern includes. If your pattern matches optional trailing spaces, {@Self} will include those spaces, which might lead to double-spacing in the output if not intended.
  • Critique: It is functionally equivalent to & in many Unix sed implementations or $0 in some regex engines, making it highly familiar to systems programmers.
  • See Also: Refer to Topic 792 ({@Param}) for accessing specific parts of the match.

Examples

Whitespace
				
					using uCalcSoftware;

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

t.FromTo("Hello World", "<{@Self}>");
Console.WriteLine(t.Transform("Hello World. HelloWorld. Hello     World. Hello, World."));
				
			
<Hello World>. HelloWorld. <Hello     World>. Hello, World.
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

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

   t.FromTo("Hello World", "<{@Self}>");
   cout << t.Transform("Hello World. HelloWorld. Hello     World. Hello, World.") << endl;
}
				
			
<Hello World>. HelloWorld. <Hello     World>. Hello, World.
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      Dim t = uc.NewTransformer()
      
      t.FromTo("Hello World", "<{@Self}>")
      Console.WriteLine(t.Transform("Hello World. HelloWorld. Hello     World. Hello, World."))
   End Sub
End Module
				
			
<Hello World>. HelloWorld. <Hello     World>. Hello, World.