Ansicht
Dokumentation

ABENREGEX_EXCEPTIONS - REGEX EXCEPTIONS

ABENREGEX_EXCEPTIONS - REGEX EXCEPTIONS

ABAP Short Reference   BAL Application Log Documentation  
This documentation is copyright by SAP AG.
SAP E-Book

- Exceptions

Invalid regular expressions that are known statically lead to syntax errors. Errors that are recognized during processing lead to catchable exceptions of classes CX_SY_REGEX_... or CX_SY_..._REGEX.... Such exceptions can occur due to invalid syntax or invalid operations.

A special exception can occur for a regular expression that has correct syntax but is too complex. Then, it cannot be executed by the libraries that are integrated in the ABAP Kernel and 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 for regular expressions that have been programmed disadvantageously or are inadequate because they would lead to extensive backtracking for certain texts.

Notes

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

Example

The following code section demonstrates that a rather simple regular expression .*X.* leads to an exception in the POSIX library if the text is several hundred characters or longer. This is a result of the leftmost-longest rule and the greedy behavior of the chaining operator * where all occurrences of substrings that match the first part of the regular expression (.*) are saved internally until the last X has been found. In POSIX regular expressions, a chaining like .*, which matches any number of substrings, should therefore be avoided at the beginning of a regular expression. In the PCRE library, the same combination of regular expression and text does not lead to an exception. Nevertheless, the last part of the example shows that unfavorable combinations can also lead to an exception in the PCRE library.

In the case of .*X.*, a search is successful for every character string that contains at least one X and any number of other characters. For such a search, the use of a regular expression is not necessary at all and can be replaced by

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

or by

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






CPI1466 during Backup   TXBHW - Original Tax Base Amount in Local Currency  
This documentation is copyright by SAP AG.

Length: 3730 Date: 20240423 Time: 162854     sap01-206 ( 65 ms )