util.Regexp.compile

Compiles a regular expression and returns a util.Regexp object.

Syntax

util.Regexp.compile(
  expr STRING
 )
  RETURNS util.Regexp
  1. expr is the regular expression to be compiled.

Usage

The util.Regexp.compile() class method compiles the pattern passed as parameter, and creates an object of type util.Regexp, that can then be used to process strings.

If the regular expression is invalid, error -8136 is raised and the method returns NULL.

Since this method returns an object that can be used in an expression, you must use a TRY/CATCH block to handle exceptions. See Understanding exceptions.

Define a variable of type util.Regexp to hold a reference to the object returned by the compile() method.

Note: When using single or double quoted string literals, backslash is interpreted as escape character. Consider using back quotes as delimiters for regular expressions strings, and use backslash characters directly as required by the regexp syntax ( `\b` instead of "\\b" or '\\b' )

See Regular expression patterns for details about the regular expression patterns accepted by the compile() method.

Example

IMPORT util
MAIN
    DEFINE re util.Regexp
    TRY
        LET re = util.Regexp.compile(`[abcdef]`)
    CATCH
        DISPLAY "Invalid regular expression!"
        EXIT PROGRAM 1
    END TRY
END MAIN