|
<< Click to Display Table of Contents >> Navigation: 3. Script Language > String commands > !BLO.-Block-Commands > Content Extraction > String Operations |
MiniRobotLanguage (MRL)
BLO.MultiGetNth
Gets the Nth block using multiple literal start and end delimiters.
Intention
This Command extracts the Nth top-level block from a source string using multiple possible start and end delimiters, provided as comma-separated lists.
It is ideal when the input text may use inconsistent or variant delimiters (e.g., both "[*]" and "<*>" for the same logical block type).
The system automatically sorts all delimiters by length in descending order and uses longest-match-first logic to avoid partial matches (e.g., prefers "[**]" over "[*" if both are in the list and match at the same position).
Note: Delimiters must not contain commas, as comma is the list separator.
Visual Example
Parsing with Mixed Delimiters
Source String: abc[*]HELLO[*]def<**>WORLD</**>xyz[##]TEST[##]
Start Delims: "[*],<**>,[##]"
End Delims: "[*],</**>,[##]"
└───┬───┘ └────┬────┘ └───┬───┘
│ │ │
▼ ▼ ▼
Result (N=1): "HELLO"
Result (N=2): "WORLD"
Result (N=3): "TEST"
Syntax
BLO.MultiGetNth|P1|P2|P3|P4[|P5]
Parameter Explanation
•P1 - (Input, Text) The source string to search within.
•P2 - (Input, Text) Comma-separated list of start delimiters (e.g., "[*],<**>").
•P3 - (Input, Text) Comma-separated list of end delimiters (e.g., "[*],</**>").
•P4 - (Input, Numeric) The block index to retrieve. 1 = first, -1 = last.
•P5 - (Output, Variable) The variable to store the extracted block content. If omitted, result is placed on Top of Stack (TOS).
Example
'***********************************
' BLO.MultiGetNth Example
'***********************************
$$SRC=abc[*]HELLO[*]def<**>WORLD</**>xyz
BLO.MultiGetNth|$$SRC|[*],<**>|[*],</**>|1|$$RES
' $$RES now contains: "HELLO"
' Get the last block
BLO.MultiGetNth|$$SRC|[*],<**>|[*],</**>|-1|$$LAS
' $$LAS = "WORLD"
' Mixed bracket styles
$$TEXT={ITEM}Apple{END}[ITEM]Orange[END]
BLO.MultiGetNth|$$TEXT|{ITEM},[ITEM]|{END},[END]|2|$$SEC
' $$SEC = "Orange"
MBX.!|$$SEC
ENR.
See also:
• BLO.AIGetNth - Gets Nth block using AI-resilient delimiters
• BLO.PatternGetNth - Gets Nth block using abstract patterns (WR_AW)