Get all occurrences of the string between any two specific characters in SAP ABAP


I usually use REGEX in all such cases as it is faster and easily readable and would recommend the same to you.

You can use something similar as the snippet to get your job done.

DATA: lv_para TYPE string.
lv_para = ' You &are like& kite &flying& in a &hurricane&'.
REPLACE ALL OCCURRENCES OF REGEX '&[^&]+&' IN lv_para WITH ''.
WRITE lv_para.

Let me explain the regex for you. It should match the first ‘&’, then you can have any combination with multiple occurrences of ‘&’ and the last occurrence of ‘&’ must be matched.

Updated on: 13-Feb-2020

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements