Efficient Data Extraction Using the Rexx PARSE Instruction
Learn how to use Rexx PARSE with positional and pattern templates to extract data from fixed-width and delimited text without using regular expressions.
04 Oct 2026, 16:57 UTC

Solving Text Extraction Without Regular Expressions
The most direct way to split structured text in Rexx is the PARSE instruction. Rather than implementing complex loops or relying on external libraries for regular expressions, PARSE allows you to extract data using either absolute character positions or literal pattern markers. This is the primary mechanism for handling fixed-width files and delimited log entries in Rexx environments like Regina, Open Object Rexx, and TSO/E.
Positional vs. Pattern Templates
Rexx supports two distinct modes of parsing within a single instruction:
- Positional Parsing: Uses integers to define fixed-width columns. These numbers represent absolute character offsets from the start of the string.
- Pattern Parsing: Uses literal strings (enclosed in quotes) as delimiters. Rexx extracts the text found between these markers and assigns it to the specified variables.
For simple whitespace-delimited strings, PARSE VAR input var1 var2 splits the source by spaces. Adding the UPPER keyword (e.g., PARSE UPPER VAR...) converts the source to uppercase before the split occurs, which is useful for case-insensitive command processing.
Worked Example: Hybrid Log Parsing
In many engineering scenarios, logs contain a mix of fixed-width identifiers and delimited metadata. Consider a log line where the first 10 characters are a system ID, followed by a status message delimited by markers: SYS001 Status: OK at 12:00.
/* Run in Regina Rexx or Open Object Rexx */
log_line = "SYS001 Status: OK at 12:00."
/* 10: extract first 10 chars into 'sysid'
'Status: ': marker for start of status
' at ': marker for end of status and start of time
'.': final marker to terminate time extraction */
parse var log_line 10 'Status: ' status ' at ' time '.'
say "System: " sysid
say "Status: " status
say "Time: " timeIn this configuration, 10 tells Rexx to take characters 1 through 10. The subsequent literal strings act as anchors, extracting only the variable data between them.
Verification and Testing
To verify the logic in a shell environment using Regina Rexx, run the following command:
rexx -e 'line="ID=007 Status=OK"; parse var line "ID=" id 9 "Status=" status; say id status'The expected output is 007 OK. This confirms that the interpreter is correctly handling the transition from a pattern marker ("ID=") to a positional offset (9).
Limitations and Engineering Risks
Absolute Offset Errors: Positional numbers are not relative to the previous match; they are absolute indices from the start of the string. If you specify 10 and then 20, the second variable starts at character 20, regardless of how many characters were consumed by the first variable. Miscalculating these offsets results in silent data corruption where the wrong substring is assigned.
Case Sensitivity: Pattern matching is strictly case-sensitive. If the log contains "status:" but your template uses 'Status:', the match will fail. To mitigate this, use PARSE UPPER VAR to normalize the source text before parsing.
Lack of Regex: Rexx does not include built-in Perl-compatible regular expressions. For patterns that vary in length or format (e.g., extracting an IP address with unknown digits), you must use a DO WHILE loop combined with the SUBSTR function or an external library.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.