Skip to content

ABAP Keyword Documentation →  ABAP − Reference →  Processing Internal Data →  Character String and Byte String Processing →  Statements for Character String and Byte String Processing →  REPLACE →  REPLACE pattern IN 

REPLACE - pattern

Quick Reference

Other versions: 7.31 | 7.40 | 7.54

Syntax


...  {[SUBSTRING] substring} | {REGEX regex} ... . 

Effect

Defines a search pattern for the statements REPLACE and REPLACE IN TABLE.

  • If substring is specified, the exact substring specified in substring is found. The optional addition SUBSTRING can be specified in front of substring for extra emphasis.
  • If REGEX is specified, the substring is found that matches a regular expression specified in regex.

substring and a directly specified regex are character-like expression positions. The syntax and semantics are the same as in the definition of a search pattern for the statement FIND. The statement REPLACE replaces the substring in question in accordance with the information specified after WITH.


Note

A regular expression can be have correct syntax, but be too complex for the execution of the statement REPLACE, which raises a handleable exception of the class CX_SY_REGEX_TOO_COMPLEX. See Exceptions in Regular Expressions.


Example

Replaces the substring "all" with "er".

DATA(str) = `Hallo`. 
REPLACE SUBSTRING `all` IN str WITH `er`. 
cl_demo_output=>display( str ).

Example

The following replacement with regular expression \D removes all non-digits from a string.

DATA(str) = `4 Apples + 2 Oranges`. 
REPLACE ALL OCCURRENCES OF REGEX `\D` IN str WITH ``. 
cl_demo_output=>display( str ).