Skip to content

ABAP Keyword Documentation →  ABAP - Reference →  Processing Internal Data →  Character String and Byte String Processing →  Expressions and Functions for String Processing →  Regular Expressions →  Syntax of Regular Expressions 

Simplified Regular Expressions

In addition to the regular expressions (in accordance with the extended POSIX standard IEEE 1003.1), the class CL_ABAP_REGEX also offers an alternative type of simplified regular expression with restricted functions. These simplified regular expressions (also known as simplified expressions) do not support all POSIX operators and use a slightly different syntax in parts. The semantics of regular expressions and simplified expressions are, however, the same.

Other versions: 7.31 | 7.40 | 7.54

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

This table demonstrates that many special characters in the regular syntax are ignored in the simplified syntax. Parentheses and curly brackets need to be escaped using the character \ if they are to keep their function in the regular syntax.


Notes

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

  • The simplified syntax corresponds to the syntax of regular expressions in the command grep on Unix.

Example

This table shows the differences in parentheses between regular syntax and simplified syntax. The final two columns show examples to which the expressions in the first column are suited (depending on the syntax used).

Pattern Regular Syntax Simplified Syntax
(.) a (a)
(.) (a) a


Example

The first search uses regular syntax and finds the first three letters "aaa". The second search has simplified syntax, where "+" does not have any meaning as a special character, and finds the substring "a+" from offset 2.

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

CREATE OBJECT regex 
  EXPORTING 
    pattern      = 'a+' 
    simple_regex = abap_false. 
FIND ALL OCCURRENCES OF REGEX regex IN 'aaa+bbb' RESULTS res. 

CREATE OBJECT regex 
  EXPORTING 
    pattern      = 'a+' 
    simple_regex = abap_true. 
FIND ALL OCCURRENCES OF REGEX regex IN 'aaa+bbb' RESULTS res.