Ansicht
Dokumentation

ABENREGEX_XPATH_SYNTAX - REGEX XPATH SYNTAX

ABENREGEX_XPATH_SYNTAX - REGEX XPATH SYNTAX

General Data in Customer Master   General Material Data  
This documentation is copyright by SAP AG.
SAP E-Book

- XPath Syntax

Regular expressions with XPath syntax can be specified behind the argument xpath of built-in functions for strings. Objects for XPath regular expressions can be created with the factory method CREATE_XPATH2 of the system class CL_ABAP_REGEX to be used in statements FIND and REPLACE or with the system class CL_ABAP_MATCHER.

Currently, there is no detailed description of the XPath syntax for regular expressions in the ABAP keyword documentation.

  • For a short syntax overview, see
Special Characters in XPath Regular Expressions
  • For the complete documentation, please refer to
XQuery 1.0 and XPath 2.0 Functions and Operators.

A regular expression in XPath syntax can be compiled in a normal and 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 built-in functions, the extended mode is switched on by default and can be switched off with (?-x) in the regular expression. When using CL_ABAP_REGEX, it can be switched by the parameter EXTENDED of method CREATE_XPATH2.

Notes

  • A regular expression with XPath syntax cannot be specified directly as a character string in the statements FIND and REPLACE, but you can use objects of CL_ABAP_REGEX that are created with method CREATE_XPATH2 with the addition REGEX instead.
  • The test and demonstration program DEMO_REGEX allows XPath syntax to be tested by selecting XPath.

A special feature of XPath regular expressions is the subtraction of character sets. In the following example, the letters a to c are subtracted from character set BasicLatin and the first match is d at offset 3.

Compared to PCRE, XPath regular expressions allow the escape character \ not only in front of special characters. The match function with parameter xpath finds x while the match function with parameter pcre does not. Accordingly the first FIND statement returns in sy-subrc the value 0 while the second FIND statement returns 4.

XPath regular expression






Addresses (Business Address Services)   Addresses (Business Address Services)  
This documentation is copyright by SAP AG.

Length: 3841 Date: 20240419 Time: 125116     sap01-206 ( 35 ms )