A practical example that extracts all `<a>` tags, but only from within a specific `<nav>` section of an HTML document.

ID: 1240

				
					using uCalcSoftware;

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

// Ignore multi-line formatting
t.DefaultRuleSet.StatementSensitive = false;

// 1. Parent rule captures the content of the <nav> block.
var navRule = t.Pattern("<nav>{content}</nav>");

// 2. Get the local transformer for the nav block.
var local_t = navRule.LocalTransformer;

// 3. This rule will only find `<a>` tags inside the <nav> block.
local_t.Pattern("<a href={url}>{text}</a>");

var html = """
<nav>
  <a href="/home">Home</a>
  <a href="/about">About</a>
</nav>
<main>
  <p>Some text with another <a href="/other">other link</a>.</p>
</main>
""";

t.Text = html;
t.Find();

Console.WriteLine("--- Found Links (Innermost Matches Only) ---");
// Use InnermostOnly to see only the results from the local transformer.
Console.WriteLine(t.GetMatches(MatchesOption.InnermostOnly).Text);
				
			
--- Found Links (Innermost Matches Only) ---
<a href="/home">Home</a>
<a href="/about">About</a>
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

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

   // Ignore multi-line formatting
   t.DefaultRuleSet().StatementSensitive(false);

   // 1. Parent rule captures the content of the <nav> block.
   auto navRule = t.Pattern("<nav>{content}</nav>");

   // 2. Get the local transformer for the nav block.
   auto local_t = navRule.LocalTransformer();

   // 3. This rule will only find `<a>` tags inside the <nav> block.
   local_t.Pattern("<a href={url}>{text}</a>");

   auto html = R"(<nav>
  <a href="/home">Home</a>
  <a href="/about">About</a>
</nav>
<main>
  <p>Some text with another <a href="/other">other link</a>.</p>
</main>)";

   t.Text(html);
   t.Find();

   cout << "--- Found Links (Innermost Matches Only) ---" << endl;
   // Use InnermostOnly to see only the results from the local transformer.
   cout << t.GetMatches(MatchesOption::InnermostOnly).Text() << endl;
}
				
			
--- Found Links (Innermost Matches Only) ---
<a href="/home">Home</a>
<a href="/about">About</a>
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      Dim t = uc.NewTransformer()
      
      '// Ignore multi-line formatting
      t.DefaultRuleSet.StatementSensitive = false
      
      '// 1. Parent rule captures the content of the <nav> block.
      Dim navRule = t.Pattern("<nav>{content}</nav>")
      
      '// 2. Get the local transformer for the nav block.
      Dim local_t = navRule.LocalTransformer
      
      '// 3. This rule will only find `<a>` tags inside the <nav> block.
      local_t.Pattern("<a href={url}>{text}</a>")
      
      Dim html = "<nav>
  <a href=""/home"">Home</a>
  <a href=""/about"">About</a>
</nav>
<main>
  <p>Some text with another <a href=""/other"">other link</a>.</p>
</main>"
      
      t.Text = html
      t.Find()
      
      Console.WriteLine("--- Found Links (Innermost Matches Only) ---")
      '// Use InnermostOnly to see only the results from the local transformer.
      Console.WriteLine(t.GetMatches(MatchesOption.InnermostOnly).Text)
   End Sub
End Module
				
			
--- Found Links (Innermost Matches Only) ---
<a href="/home">Home</a>
<a href="/about">About</a>