REGEX
The REGEX PL/B object provides compiled regular-expression support for matching, searching, counting, replacing, and splitting text. A regular expression (regex) is a sequence of characters that forms a specific search pattern.The declaration syntax of a REGEX object is as follows:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Where:
label
Optional. A Data Label.
%
Optional. Denotes the item as being GLOBAL.
arraysize
Required. An integer decimal constant, CONST variable, or EQUATEd value indicating the number of array items.
^
Optional. Denotes the item as being a POINTER.
target
Required. The name of a previously defined data item of the same type.
Flags Affected: NONE
Instructions:
Object instructions are PL/B verbs that support the graphical objects.
|
Release the data structures obtained for an object. |
Methods:
Methods are encapsulated routines that act upon an object.
|
Stores pattern for later compiled calls. | |
|
Returns of matches found from compiled pattern. | |
|
Returns the last successful matched substring. | |
|
Returns the maximum capture count. | |
|
Used to test whether a compiled pattern is present. | |
|
Checks for a matching substring. | |
|
Used to obtain a matching substring. | |
|
Used to obtain all matching substrings. | |
|
Used to replace a matching substring. | |
|
Used to replace all matching substrings. | |
|
Used to replace targeted matching substrings. | |
|
Used to reset a REGEX object. | |
|
Used to find the position of a matching substring. | |
|
Used to split a string into substrings using the stored.regular expression. | |
|
Used to check for a matching substring using a provided.regular expression. |
Note the following:
The REGEX object is implicitly created when a method is executed.
A REGEX object maintains a compiled pattern and a last-match cache, read with GetMatch the method.
Methods that use the compiled pattern are IsMatch, Match, MatchAll, Search, Count, Replace, ReplaceAll, ReplaceEx, and Split.
The Test method is a one-shot call. It compiles the supplied pattern for that call only and does not replace the object's compiled pattern.
The GetMatch method returns the object's cached last match. A match can be empty (zero-length), so an empty GetMatch does not by itself mean there was no match.
The last-match cache is cleared by the Compile method, Reset method and any method call that finds no match.
Methods that use the compiled pattern return 0, an empty string, or the text unchanged when no pattern is compiled. Use the IsCompiled method to tell this apart from "no match".
The REGEX object can be used in a DESTROY instruction.
See Also: Object Definitions, Regular Expression Support
![]() |