Ansicht
Dokumentation

ABENREGEX_SYSTEM_CLASSES - REGEX SYSTEM CLASSES

ABENREGEX_SYSTEM_CLASSES - REGEX SYSTEM CLASSES

SUBST_MERGE_LIST - merge external lists to one complete list with #if... logic for R3up   General Data in Customer Master  
This documentation is copyright by SAP AG.
SAP E-Book

- System Classes

The system classes for regular expressions are CL_ABAP_REGEX and CL_ABAP_MATCHER. Both are documented in the class library.

CL_ABAP_REGEX

Factory methods of class CL_ABAP_REGEX create an object-oriented representation of a regular expression passed in a character-like field:

  • CREATE_PCRE creates instances for regular expressions with PCRE syntax.
  • CREATE_XPATH2 creates instances for regular expressions with XPath syntax.
  • CREATE_XSD creates instances for regular expressions with XSD syntax.
  • CREATE_POSIX creates instances for regular expressions with POSIX syntax (obsolete).

Optional parameters allow further specifications for handling the regular expression:

  • The Parameter EXTENDED for CREATE_PCRE and CREATE_XPATH2 switches the extended mode for compiling PCRE and XPath expressions. The default value is ABAP_TRUE. In the extended mode, most unescaped whitespace (blanks and line breaks) of the pattern are ignored outside character classes and comments can be placed behind #. In order to include whitespace and # into a pattern, they must be escaped The extended mode can also be switched of with (?-x) in the regular expression.
  • The Parameter UNICODE_HANDLING for CREATE_PCRE and CREATE_XPATH2 defines how characters from the surrogate area are handled.

Instances of CL_ABAP_REGEX can be used with the class CL_ABAP_MATCHER and with the addition REGEX of the statements FIND and REPLACE.

Notes

  • The class CL_ABAP_REGEX can also be instantiated with the operator NEW or the statement CREATE OBJECT, but this is deprecated. Such a direct instantiation of CL_ABAP_REGEX creates instances for regular expressions with POSIX syntax. Instead of direct instantiation, the above factory methods CREATE_PCRE, CREATE_POSIX, CREATE_XPATH2 or CREATE_XSD should be used.
  • Instances of CL_ABAP_REGEX for all kinds of regular expressions, PCRE, XPath, XSD and POSIX (obsolete) can be used with the addition REGEX of the statements FIND and REPLACE. This circumvents the restriction that regular expressions of XPath and XSD syntax cannot be specified directly as character strings.
  • Instances of CL_ABAP_REGEX cannot be used with the addition PCRE of the statements FIND and REPLACE.

Search for a regular expression

CL_ABAP_MATCHER

The class CL_ABAP_MATCHER applies regular expressions to either a character string or an internal table. Its methods allow finding, replacing or matching regular expressions. Instances of CL_ABAP_MATCHER can be created either with factory methods of the class itself or with the method CREATE_MATCHER of the class CL_ABAP_REGEX. The latter allows the use of the same regular expression multiple times for different texts.

The class CL_ABAP_MATCHER stores the current state of text processing. The current processing state can be queried using different GET_... methods.

For PCRE syntax, the class CL_ABAP_MATCHER supports callouts. With the method SET_CALLOUT a handler class can be registered that implements the interface IF_ABAP_MATCHER_CALLOUT. The special characters (?C...) of a PCRE regular expression then call the interface method CALLOUT when the method MATCH is executed.

Note

If a regular expression has to be used several times, it is preferable to work with objects of CL_ABAP_MATCHER created with CL_ABAP_REGEX.

Example

An object of CL_ABAP_MATCHER is created with the method CREATE_MATCHER of an instance of the class CL_ABAP_REGEX that represents a regular expression with PCRE syntax. Depending on a successful match, the registered subgroups of submatches are received and displayed.






BAL_S_LOG - Application Log: Log header data   General Material Data  
This documentation is copyright by SAP AG.

Length: 6368 Date: 20240425 Time: 113032     sap01-206 ( 106 ms )