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:

 

(1)

[label]

REGEX

[%|^][(arraysize)]

(2)

[label]

REGEX

^,{target}

(3)

[label]

REGEX

^(arraysize),({target}),...,({target})

 

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.

 

DESTROY

Release the data structures obtained for an object.

 

Methods:

 

Methods are encapsulated routines that act upon an object.

 

Compile

Stores pattern for later compiled calls.

Count

Returns of matches found from compiled pattern.

GetMatch

Returns the last successful matched substring.

GetMaxCaptures

Returns the maximum capture count.

IsCompiled

Used to test whether a compiled pattern is present.

IsMatch

Checks for a matching substring.

Match

Used to obtain a matching substring.

MatchAll

Used to obtain all matching substrings.

Replace

Used to replace a matching substring.

ReplaceAll

Used to replace all matching substrings.

ReplaceEx

Used to replace targeted matching substrings.

Reset

Used to reset a REGEX object.

Search

Used to find the position of a matching substring.

Split

Used to split a string into substrings using the stored.regular expression.

Test

Used to check for a matching substring using a provided.regular expression.

 

Note the following:

  1. The REGEX object is implicitly created when a method is executed.

  2. A REGEX object maintains a compiled pattern and a last-match cache, read with GetMatch the method.

  3. Methods that use the compiled pattern are IsMatch, Match, MatchAll, Search, Count, Replace, ReplaceAll, ReplaceEx, and Split.

  4. 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.

  5. 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.

  6. The last-match cache is cleared by the Compile method, Reset method and any method call that finds no match.

  7. 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".

  8. The REGEX object can be used in a DESTROY instruction.

 

 

See Also: Object Definitions, Regular Expression Support

 



PL/B Language Reference