Testing Regular Expressions

The following program section can be used for testing regular expressions:

DATA: matcher TYPE REF TO cl_abap_matcher,
      match   TYPE c LENGTH 1.

matcher = cl_abap_matcher=>create( pattern     = ...
                                   ignore_case = ...
                                   text        = ... ).

match = matcher->match( ).

The data object match contains the value "X" if the regular expression transferred to pattern matches the character string transferred to text.

The following program has the same functions, but works using explicit generation of an object of the class CL_ABAP_REGEX. If the same regular expression is used several times for different texts, this form is better for performance than the shorter version above.

DATA: regex   TYPE REF TO cl_abap_regex,
      matcher TYPE REF TO cl_abap_matcher,
      match   TYPE c LENGTH 1.

CREATE OBJECT regex EXPORTING pattern     = ...
                              ignore_case = ... .

matcher = regex->create_matcher( text = ... ).

match = matcher->match( ).