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 →Testing Regular Expressions
Predefined functions or system classes can be used to test regular functions.
Using Predefined Functions
The predicate function matches can be used as follows to test whether a regular expression passed to regex matches the character string passed to val:
The function matches is handled like a relational expression and can be used as a logical expression, for example behind IF (see example for matches). The function is case-sensitive. If the test is not case-sensitive, the content must be converted accordingly before or during the function call. System classes can also be used.
Using System Classes
The system classes for regular expressions are CL_ABAP_REGEX and CL_ABAP_MATCHER.
CL_ABAP_MATCHER is enough for simple tests of regular expressions:
The data object match contains the value "X" if the regular expression passed in pattern matches the character string passed in text.
The following program works in the same way, but creates an object of the class CL_ABAP_REGEX explicitly. This form has better performance than the short form above if the same regular expression is used multiple times for different texts.