

SQL FunctionĬhecks whether a string contains any occurrence of PCREĬounts and returns all occurrences of a PCREĪ PCRE is replaced in a string with another specified character string The regular expressions of general ABAP work with the PCRE2 library implemented in the ABAP Kernel. These functions access the PCRE1 library implemented in the SAP HANA database. PCRE syntax for ABAP SQL and ABAP CDSĪBAP SQL and ABAP CDS also support the PCRE syntax with the built-in functions REPLACE_REGEXPR, LIKE_REGEXPR and OCCURRENCES_REGEXPR. When the regular expression is matched, the interface method CALLOUT is called for each callout position and can access the passed parameter. The first three callouts pass numerical data, the other two pass string data.Ī local class ‘handle_regex’ implements the interface IF_ABAP_MATCHER_CALLOUT and an instance of that class is set as the callout handler. The regular expression contains the special characters (?C…) for callouts. \w| ).ĭATA(regex) = cl_abap_regex=>create_pcre( Matches a whitespace character - that is, a space or tabįrom what mentioned above, we can write regular expressions like this: Matches any letter, digit and underscore character Special Characterĭefinition of a value set for single charactersĭefinition of a range in a value set for single charactersĬoncatenation of any number of single characters including ‘no characters’Ĭoncatenation of any number of single characters excluding ‘no characters’ I try to cover some of the commonly used symbols in the table below. Regular Expressions are generally composed of symbols and characters (literals). Class CL_ABAP_MATCHER applies a regular expression generated using CL_ABAP_REGEX to either a character string or an internal table. Using RegEx, it would be easy to search and find all the seven character: FIND ALL OCCURRENCES OF PCRE '' IN 'ABCD1234EFG'ĪBAP supports Regex in the statements FIND and REPLACE and via the classes CL_ABAP_REGEX and CL_ABAP_MATCHER.

Now if you want to find all alphabets in the string without using RegEx and by means of normal search pattern, you need a loop over all the 26 characters. Let’s take this simple example: FIND 'A' IN 'ABCD1234EFG' Also, in ABAP, a search using a regular expression is more powerful than traditional SAP patterns. Many text search and replacement problems are difficult to handle without using regular expression pattern matching. Like searching for numbers, alphabets, special characters or validating an Email etc. It is used when complex patterns are expected. RegEx concept is around for quite some time.
#Regex for number free
Those of you who are an expert of this topic and might be get bored, please feel free to skip this section ahead. Before digging into the new features, I would like to give a short introduction on RegEx in general & presenting examples which is explicitly written in ABAP. Regular expressions, or regex as they’re commonly called, are usually complicated and intimidating for new users. Although this can be hidden by the pragma #regex_posix, it is strongly recommended to migrated to the other regular expression syntax supported by ABAP like PCRE regular expressions, XPath regular expressions or XSD regular expressions. Hence, from now on, regular expressions in POSIX syntax are obsolete, then using this kind of regular expressions syntax leads to a warning from the syntax check. Previously, POSIX style regular expressions or “Portable Operating System Interface for uniX” was used in ABAP. In this blog post, I would like to share the latest news and changes made to Regular Expressions in modern ABAP, mainly from OP release 7.55 & 7.56.
