SAP NetWeaver AS ABAP Release 740, ©Copyright 2014 SAP AG. All rights reserved.
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.
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 |
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
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.