SAP REGEX MTCH



Get Example source ABAP code based on a different SAP table
  


VERSION 5 IN

ABAP_REGEX - Searching, Replacing, Matching
Regular expressions can be used to find and replace substrings of character strings or to check if a complete character string matches its pattern. If a regular expression is applied to a character string as a search pattern, a search for matches of the regular expression with substrings of the character string is intended. In this case, special characters in the regular expression do not match characters, but match positions, thus affecting the type and number of occurrences. If a regular expression is applied to a character string as a match pattern, it is checked whether the character string matches a pattern.
ITOC



Latest notes:

A regular expression in PCRE or XPath syntax can be compiled in a normal or extended mode. 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 ABAP statements and built-in functions, the extended mode is switched on by default. It can be switched of with the special character (?-x) in the regular expression. When using CL_ABAP_REGEX, it can be switched by the parameter EXTENDED of method CREATE_PCRE.
NON_V5_HINTS
ABAP_HINT_END

Searching
In order to search for substrings that match a pattern described by a regular expression you can use the following:
Statement FIND with the addition PCRE$|REGEX.
Built-in functions with the argument pcre$|xpath and with regex (obsolete):
find, find_...
count, count_...
match
substring, substring_...
contains...
Methods of system class CL_ABAP_MATCHER.

ABAP_EXAMPLE_VX5
Demonstration of different possibilities for searching substrings that match a regular expression.
ABEXA 01451
ABAP_EXAMPLE_END

Replacing
In order to replace substrings that match a pattern described by a regular expression, the following can be used:
Statement REPLACE with the addition PCRE$|REGEX.
Built-in function replace with the argument pcre or regex (obsolete).
Methods of the system class CL_ABAP_MATCHER.

ABAP_EXAMPLE_VX5
Demonstration of different possibilities for replacing substrings that match a regular expression.
ABEXA 01452
ABAP_EXAMPLE_END

Matching
In order to check if a complete character string matches a regular expression, the following can be used:
Built-in function matches with the argument pcre$|xpath or regex (obsolete).
Methods of system class CL_ABAP_MATCHER.

ABAP_EXAMPLE_VX5
Demonstration of different possibilities for matching strings with a regular expression.
ABEXA 01453
ABAP_EXAMPLE_END