|
<< Click to Display Table of Contents >> Navigation: 3. Script Language > String commands > !BLO.-Block-Commands > Content Extraction > String Operations |
MiniRobotLanguage (MRL)
BLO.PatternGetNth
Gets the Nth block using abstract pattern-based delimiters.
Intention
This Command extracts the Nth top-level block from a source string where delimiters are defined not as fixed strings, but as abstract patterns matched by the system’s WR_AW function.
It supports variable-length delimiters (1–20 characters) and uses longest-match-first logic to avoid partial matches (e.g., prefers "[**]" over "[*" when both could match).
If the end delimiter pattern is omitted, the start pattern is used for both.
Visual Example
Extracting with Pattern-Based Delimiters
Source String: abc[*]&OR:[*]HELLO[*]&OR:[/*]def[*]&OR:[*]WORLD[*]&OR:[/*]xyz
└──────┬───────┘ └──────┬───────┘
│ │
▼ ▼
Result (N=1): "HELLO"
Result (N=2): "WORLD"
Syntax
BLO.PatternGetNth|P1|P2|P3|P4|P5[|P6]
Parameter Explanation
•P1 - (Input, Text) The source string to search within.
•P2 - (Input, Text) The start delimiter pattern (e.g., "[*]&OR:[*").
•P3 - (Input, Text) The end delimiter pattern. If empty, P2 is used for both.
•P4 - (Input, Numeric) The block index to retrieve. 1 = first, -1 = last, etc.
•P5 - (Output, Variable) The variable to store the extracted block content.
•P6 - (Optional, Numeric) Maximum delimiter length to test (default = 5, max = 20).
Example
'***********************************
' BLO.PatternGetNth Example
'***********************************
$$SRC=abc[*]&OR:[*]HELLO[*]&OR:[/*]def[*]&OR:[*]WORLD[*]&OR:[/*]xyz
BLO.PatternGetNth|$$SRC|[*]&OR:[*|[*]&OR:[/*]|1|$$RES
' $$RES now contains: "HELLO"
' Get the last block (-1)
BLO.PatternGetNth|$$SRC|[*]&OR:[*|[*]&OR:[/*]|-1|$$LAS
' $$LAS now contains: "WORLD"
' Use default end delimiter (same as start)
BLO.PatternGetNth|$$SRC|[*]&OR:[*||2|$$BLO
MBX.!|$$BLO
ENR.
See also:
• BLO.AIGetNth - Gets Nth block using AI-resilient literal delimiters
• BLO.MultiGetNth - Gets Nth block using multiple literal delimiters