Simplified Regular Expressions

In addition to the regular expressions according to the extended POSIX standard IEEE 1003.1, the class CL_ABAP_REGEX also offers an alternative type of simplified regular expressions with restricted functionality. These simplified regular expressions (also known as simplified expressions) do not support all POSIX operators and use a slightly varying syntax. The semantics of regular expressions and simplified expressions is, however, the same.

Simplified syntax

The following table provides an overview of the syntax differences between regular expressions and simplified regular expressions.

Regular syntax Simplified syntax
* *
+ not supported
{ } \{ \}
( ) \( \)
[ ] [ ]
| not supported
(?= ) (?! ) not supported
(?: ) not supported

Note

Regular expressions with simplified syntax can only be used within the class CL_ABAP_REGEX. If the value 'X' is transferred for the input parameter simple_regex, the regular expression is viewed according to the simplified syntax. By default, the syntax is used according to the extended POSIX standard. If the simplified syntax is to be used in the statements FIND or REPLACE, an object must be transferred.

Example

Regular expression Simplified expression Matches
(.) - a
- (.) (a)
\(.\) - (a)
- \(.\) a

Example

The following program determines all consecutive repeated double characters.

DATA: regex TYPE REF TO cl_abap_regex,
      res   TYPE        match_result_tab,
      text  TYPE        string.

CREATE OBJECT regex
    EXPORTING pattern      = '\(.\)\1'
              simple_regex = 'X'

FIND ALL OCCURRENCES OF REGEX regex IN text RESULTS res.