|
<< Click to Display Table of Contents >> Navigation: 3. Script Language > String commands > !STR.- String Command > String Replace Commands > String Operations |
MiniRobotLanguage (MRL)
STR.RetainAny
Retains only characters from a specified set (whitelist).

Intention
This Command filters a string to keep only the characters you specify. Any character NOT in your specified set is removed.
This is useful for extracting digits only, letters only, or any specific character class from mixed content.
Syntax
STR.RetainAny|P1|P2|P3
Parameter Explanation
•P1 - (Input, Text) The source string to filter.
•P2 - (Input, Text) A string containing all characters to keep (the whitelist).
•P3 - (Output, Text) Variable to store the filtered result.
Retaining Specific Characters
Source String: "Phone: (555) 123-4567"
Keep only: "0123456789"
Result: "5551234567"
Source String: "Price: $1,234.56 USD"
Keep only: "0123456789."
Result: "1234.56"
Example
'***********************************
' STR.RetainAny Example
'***********************************
$$PHONE="(555) 123-4567 ext. 42"
' Extract just the digits
STR.RetainAny|$$PHONE|0123456789|$$NUMBERS
' $$NUMBERS = "555123456742"
MBX.$$NUMBERS
' Keep only letters
$$MIXED="ABC-123-DEF-456"
STR.RetainAny|$$MIXED|ABCDEFGHIJKLMNOPQRSTUVWXYZ|$$LETTERS
' $$LETTERS = "ABCDEF"
MBX.$$LETTERS
' Keep alphanumeric only (remove special chars)
$$FILE="Report_V2.1 (Final).pdf"
STR.RetainAny|$$FILE|ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789|$$SAFE
' $$SAFE = "ReportV21Finalpdf"
MBX.$$SAFE
ENR.
Remarks
• Each character in P1 is checked individually against all characters in P2.
• The order of characters in P2 does not matter.
• This is the opposite of STR.RemoveAny, which removes the specified characters.
• For case-insensitive character filtering, include both uppercase and lowercase in P2.
See also:
• STR.RemoveAny - Remove specific characters (opposite)
• STR.RemainAny - Keep only characters (alias)
• STR.CountAny - Count specific characters