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 

Exceptions in Regular Expressions

If a regular expression has correct syntax but is too complex, it cannot be executed by the Boost.Regex Library that is integrated in the ABAP kernel. In this case, an exception of the class

  • CX_SY_REGEX_TOO_COMPLEX is raised.

A regular expression is too complex if the number of transitions exceeds a certain limit. This is usually the case if there are expressions that have been programmed incorrectly or are inadequate regular expressions that would produce extensive tracing for certain texts.

Other versions: 7.31 | 7.40 | 7.54


Note

The occurrence of the exception CX_SY_REGEX_TOO_COMPLEX depends on both the regular expression and the text to be checked. A regular expression that works for one text may raise an exception in another text.


Example

Consider the following simple search with a syntactically correct regular expression:

FIND REGEX '.*X.*' IN text.
IF sy-subrc = 0.
  ...
ENDIF.

If the text length is several hundred characters or more, this statement always raises the exception named above. As a result of the Leftmost-longest rule and the greedy behavior of the chaining operator , all occurrences of subsequences that match the first part of the regular expression (.) have to be saved internally until the last X has been found. A chaining like .*, which matches any number of subsequences, should therefore be avoided at the start of a regular expression.

The above search is successful for every character string that contains at least one X and any number of other characters. Instead of a regular expression, in this case a simple search for a subsequence or the relational operator CS can be used:

FIND SUBSTRING 'X' IN text.
IF sy-subrc = 0.
  ...
ENDIF.

or

IF text CS 'X'.
  ...
ENDIF.