|
<< Click to Display Table of Contents >> Navigation: 3. Script Language > String commands > !STR.- String Command > String Replace Commands > String Operations |
MiniRobotLanguage (MRL)
STR.Retain
Retains Specified Substrings in a String

Keep only defined substrings.
Intention
This command is used to retain only the characters in the source string that are part of exact substring matches with one or more specified match strings. All other characters are removed. The command processes multiple match strings sequentially, and once a character is retained as part of a match, it is ignored for subsequent matches to prevent overlapping or re-marking.
•The command is case-sensitive by default.
•Each match string is searched for in the source string, and only the first valid match for each character position is retained.
•Subsequent matches that include already-retained characters are ignored.
The result contains only the characters that are part of the matching substrings, in their original order.
Overlapping matches are resolved by retaining the first valid match for each character position.
Syntax
STR.Retain|P1|P2[|P3[|...|Pn]]
STR.Rtn|P1|P2[|P3[|...|Pn]]
Parameter Explanation
•P1 - (Source String) The main string from which to retain substrings. Modified directly unless P3 is provided.
•P2 - (Match String) The first substring to be retained.
•P3...Pn - (Optional Match Strings or Result Variable) Additional substrings to retain, or the variable to store the result. If the last parameter is a variable, the result is stored there; otherwise, P1 is modified.
Example
'***********************************
' STR.Retain - Sample
'***********************************
$$SRC=HelloWorldTestFooBar
STR.Retain|$$SRC|Hello|loWo|Foo
MBX.$$SRC
ENR.
Remarks
- The command processes match strings in order, retaining characters from the first valid match at each position.
- If no matches are found, the result is an empty string.
- Empty match strings are ignored.
Limitations:
- Case-sensitive by default; case-insensitive matching is not currently supported.
- Overlapping matches are resolved by retaining the first valid match for each character position.
See also: