String Operations

<< Click to Display Table of Contents >>

Navigation:  3. Script Language > String commands > !STR.- String Command > String Replace Commands >

String Operations

STR.RegExpr

Previous Top Next


MiniRobotLanguage (MRL)

 

STR.RegExpr

Matches a regular expression pattern against a string.

 

clip1152

 

Intention

 

This Command performs regular expression pattern matching to test if a string contains text that matches a specified pattern. It returns the matched text or an indicator of success.

Regular expressions provide powerful pattern matching for complex text validation and extraction tasks.

 

 

Syntax

 

STR.RegExpr|P1|P2|P3

 

Parameter Explanation

 

P1 - (Input, Text) The source string to search.

P2 - (Input, Text) The regular expression pattern to match.

P3 - (Output, Text) Variable to store the matched text, or empty if no match.

 

 

 Regular Expression Matching

 

Source: "Contact: john@email.com or jane@site.org"

Pattern: "[a-z]+@[a-z]+\.[a-z]+"

Result: "john@email.com" (first match)

 

Source: "Phone: 555-1234"

Pattern: "\d{3}-\d{4}"

Result: "555-1234"

 

 

 

Example

 

'***********************************

' STR.RegExpr Example

'***********************************

$$TEXT="Order #12345 confirmed on 2024-01-15"

 

' Extract order number

STR.RegExpr|$$TEXT|Order #(\d+)|$$ORDER

' $$ORDER = "Order #12345" (full match)

 

' Extract date (YYYY-MM-DD format)

$$DATA="Meeting scheduled for 2024-03-25 at 14:00"

STR.RegExpr|$$DATA|\d{4}-\d{2}-\d{2}|$$DATE

' $$DATE = "2024-03-25"

 

' Validate email format

$$EMAIL="user@example.com"

STR.RegExpr|$$EMAIL|^[\w.-]+@[\w.-]+\.\w+$|$$VALID

IF $$VALID<>"" THEN MBX.Valid email!

ENR.

 

Remarks

 

? Returns only the first match found in the string.

? Pattern syntax follows standard regular expression rules.

? Common patterns: \d=digit, \w=word char, .=any char, *=zero or more, +=one or more, ?=optional.

? Use ^ to anchor to start, $ to anchor to end of string.

? For complex replacements, use STR.RegReplace instead.

 

Common Patterns

 

? \d+ - One or more digits

? [A-Za-z]+ - One or more letters

? \w+@\w+\.\w+ - Simple email pattern

? https?://\S+ - URL pattern

 

See also:

 

? STR.RegReplace - Replace using regex

? STR.Contains - Simple substring check

? STR.Instr - Find position of substring