Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Find All Occurance

Hi Colleague,

I want to extract all words from a string which lie betwen &..&..

for example

Lv_string = ' Hello SAP &INDIA& in the city &Bangalore&'

i want the INDIA and Bangalore as a separate string either in a table or in loop.

Regards

Piyush

Tags:
Former Member
Former Member replied

DATA: lv_string type string,

it_result TYPE match_result_tab,

wa_result TYPE match_result,

wa_result2 TYPE match_result,

wa_first type i,

wa_second type i.

DATA : Begin of it_final occurs 0,

text type string,

end of it_final.

Lv_string = ' Hello SAP &INDIA& in the city &Bangalore&'.

FIND ALL OCCURRENCES OF REGEX '&' IN Lv_string RESULTS it_result.

loop at it_result into wa_result .

wa_first = wa_result-offset + 1.

delete it_result.

Read table it_result into wa_result2 index 1.

wa_second = wa_result2-offset - ( wa_result-offset + 1 ).

it_final-text = lv_string+wa_first(wa_second).

delete it_result index 1.

append it_final.

endloop.

loop at it_final.

write / it_final-text.

endloop.

output :

INDIA

BANGALORE.

Check and let us know.

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question