2014 Jan 28 11:42 AM
Hi everybody,
I got a string like:
data: mystring type string value 'DE11111X1111DE222222222222222ZPDE33333333333333DE44444444444'.
How can I find the string from the first <DE> to the second <DE> (= DE11111X1111) ?
I tried
data: mystring type string value 'DE1111X11111DE222222222222222ZPDE33333333333333DE44444444444'.
DATA: moff TYPE i,
mlen TYPE i.
FIND REGEX 'DE.*DE' IN mystring MATCH COUNT sy-tabix
MATCH OFFSET moff
MATCH LENGTH mlen.
write:/ mystring+moff(mlen).
But this gives:
DE1111X11111DE222222222222222ZPDE33333333333333DE
Thanks, Regards
Mario
2014 Jan 28 11:57 AM
Thanks to Manish,
I did it that way:
DATA lv_input TYPE string
VALUE 'xDE11111X1111DE222222222222222ZPDE33333333333333DE44444444444'.
DATA lv_output TYPE string.
lv_output = lv_input.
WRITE:/ lv_input.
while lv_output cs 'DE'.
REPLACE REGEX '(.)DE.*' IN lv_output WITH '$1'.
WRITE:/ lv_output.
REPLACE FIRST OCCURRENCE OF lv_output IN lv_input WITH ''.
lv_output = lv_input.
endwhile.
Regards
Mario
2014 Jan 28 11:57 AM
2014 Jan 28 12:01 PM
2014 Jan 28 12:22 PM
Hi Mario
\DE Regex will provide you the postion of DE and then you can derive accordingly
Nabheet
2014 Jan 28 12:28 PM
Hi Nabheet,
sorry. I don't understand.
When I try:
FIND REGEX '\DE' IN mystring MATCH COUNT sy-tabix
MATCH OFFSET moff
MATCH LENGTH mlen.
offset = 0,
length = 2.
Regards Mario
2014 Jan 28 12:51 PM
DE.*?DE does not work in ABAP because non-greedy regex syntax is not yet implemented.
It is reserved for future enhancements.
As a workaround, i am assuming the string starts with DE. Second DE occurrence can be found using sample below, which is then replaced with nothing.
//
2014 Jan 28 1:07 PM
Thanks to Manish,
I did it that way:
DATA lv_input TYPE string
VALUE 'xDE11111X1111DE222222222222222ZPDE33333333333333DE44444444444'.
DATA lv_output TYPE string.
lv_output = lv_input.
WRITE:/ lv_input.
while lv_output cs 'DE'.
REPLACE REGEX '(.)DE.*' IN lv_output WITH '$1'.
WRITE:/ lv_output.
REPLACE FIRST OCCURRENCE OF lv_output IN lv_input WITH ''.
lv_output = lv_input.
endwhile.
Regards
Mario
| User | Count |
|---|---|
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |