Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Find All Occurance

Former Member
0 Kudos

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

1 ACCEPTED SOLUTION

Former Member
0 Kudos

i tried to use REGEX &*&, where * is a wildcard character, so that i can get the length of the word also between &..&.

It doesnt work. I am sure that the regular expression is not correct. Any alternative

Regards

Piyush

4 REPLIES 4

valter_oliveira
Active Contributor
0 Kudos

DATA: it_result TYPE match_result_tab,
      wa_result TYPE match_result.
FIND ALL OCCURRENCES OF '&' IN Lv_string RESULTS it_result.

it_result will have a list of the offsets where '&' is in your string field.

Regards,

Valter Oliveira.

Former Member
0 Kudos

i tried to use REGEX &*&, where * is a wildcard character, so that i can get the length of the word also between &..&.

It doesnt work. I am sure that the regular expression is not correct. Any alternative

Regards

Piyush

0 Kudos

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.

Former Member
0 Kudos

Wow that was the exact solution...

Thank You