Ansicht
Dokumentation

ABAPFIND_PATTERN - FIND PATTERN

ABAPFIND_PATTERN - FIND PATTERN

Vendor Master (General Section)   Vendor Master (General Section)  
This documentation is copyright by SAP AG.
SAP E-Book

FIND, pattern

Short Reference



...  ${$[SUBSTRING$] substring$} $| ${PCRE pcre$}$|${REGEX regex_ref$} ... .

Variants:

1. ... $[SUBSTRING$] substring.

2. ... ${PCRE pcre$}$|${REGEX regex_ref$}

Effect

Definition of a search pattern for the statements FIND and FIND IN TABLE. The system can either search for exactly one substring substring or for a substring that matches a regular expression behind PCRE or REGEX.

Note

The statements REPLACE and REPLACE IN TABLE use the same search pattern.

Variant 1

... $[SUBSTRING$] substring.


Effect

In this variant, a search is performed for the exact occurrence of a substring specified in a character-like or byte-like operand substring. substring is a character-like expression position. The optional word SUBSTRING can be specified for emphasis.

If substring is either an empty string or is of type c, n, d, or t and only contains blanks, a search is performed for an empty substring. This is only possible when searching for the first occurrence, and the empty substring is always found before the first character or byte. In character string processing, the trailing blanks are ignored for substring data objects of fixed length.

Note

If trailing blanks are not to be ignored in the substring, substring must have the data type string.

Example

Search for all occurrences of the string "now" in a text string literal. The offsets 11 and 24 of both occurrences are shown in the output.

Example

Search for all occurrences of the string "now" in a text string literal using a WHILE loop. After every successful search, the search range is redefined to start after the occurrence. In this way, all occurrences of the search pattern could be found even before the addition ALL OCCURRENCES was introduced.

Variant 2

... ${PCRE pcre$}$|${REGEX regex_ref$}


Effect

In this variant, a search is performed for a substring that matches a regular expression specified in pcre or regex_ref.

  • If the addition PCRE is used, a character-like operand can be specified for pcre that contains a valid PCRE regular expression. The PCRE syntax is compiled in an extended mode: Most unescaped whitespace (blanks and line breaks) of the pattern are ignored outside character classes and comments can be placed behind #. In order to include whitespace and # into a pattern, they must be escaped or the extended mode must be switched off with (?-x) in the regular expression.

pcre is a character-like expression position.

In searches using a regular expression, special search patterns can be specified that allow further conditions including forecast conditions.

An empty string in pcre is not a valid regular expression and raises an exception. A character string is empty if pcre is either an empty string or is of type c, n, d, or t and only contains blanks.

Notes

  • Instances of CL_ABAP_REGEX for all kinds of regular expressions, PCRE, XPath, XSD and POSIX (obsolete) can be used with the addition REGEX. This circumvents the restriction that regular expressions of XPath and XSD syntax cannot be specified directly as character strings.
  • When using CL_ABAP_REGEX, the extended mode can be switched by a parameter for PCRE and XPath regular expressions.
  • Some regular expressions that are not empty, such as a*, are used to search for empty character strings. This is possible when searching for the first occurrence or all occurrences. The corresponding empty substrings are found before the first character, between all characters, and after the last character of the search range. A search of this type is always successful.

Example

The search uses PCRE regular expression syntax and finds the 'ab' from offset 3.






General Material Data   General Material Data  
This documentation is copyright by SAP AG.

Length: 7463 Date: 20240328 Time: 234756     sap01-206 ( 86 ms )