Compile Method (REGEX)


 

The Compile method is used to compile and store.a regular expression in the associated PL/B REGEX object. This method uses the following format:

 

 

[label]

{object}.Compile

[GIVING {return}] USING [*Pattern=]{pattern}[:

 

 

[*Options=]{options}]

 

Where:

label

Optional. A Program Execution Label.

object

Required. A REGEX object previously declared.

return

Optional. A Numeric Variable that returns a one for success or zero for failure.

pattern

Required. A Character String Variable or literal that specifies a valid regular expression.

options

Optional. A decimal number or Numeric Variable that has a bit mask value described below.

Flags Affected: EOS, OVER, ZERO

Notes:

  1. If the value returned is zero, the ZERO Condition Flag is set.

  2. The OVER flag is set TRUE if the 'return' variable is too small and cannot contain the 'return' value without being truncated. Otherwise, the OVER flag is set to FALSE.

  3. The EOS flag is always cleared.

  4. The {pattern} parameter contains the regular expression to be compiled.

  5. If successful the pattern is stored in the object for later compiled calls.

  6. The object's last-match cache is cleared.

  7. The {options} bit mask values found in plbmeth.inc are defined as follows:

  8.  

    Equate

    Value

    Description

    $REGEX_OPT_NOCASE

    1

    Case-insensitive (ASCII A-Z only)

    $REGEX_OPT_MULTILINE

    8

    ^ and $ also match at line breaks

    $REGEX_OPT_DOTALL

    16

    . also matches CR and LF

    $REGEX_OPT_NOTEMPTY

    32

    Reject empty (zero-length) matches

  9. The {return} value is one when the pattern compiled successfully and zero when the compile failed

  10. Patterns that fail to compile include an unclosed group or class, an empty class [], a quantifier with nothing to repeat, a quantifier on an anchor ($+, ^*), a{5,2}, a{255}, {,n}, more groups than the limit, an unknown POSIX class, an invalid \x or octal escape, a trailing backslash, a reference to a missing group, and a pattern too large. Also a class used as a range endpoint, such as [a-\d] or [[:digit:]-z] will fail to compile.

 

Example 1:

 

      RegEx1.Compile Giving N Using "Smith"

 

Example 2:

 

     RegEx1.Compile Giving N Using "^alice",$REGEX_OPT_NOCASE

 

 

See Also: Method Syntax, REGEX, Regular Expression Support



PL/B Language Reference