04-27-2020 3:54 PM
I have written a very small piece of code to know how regexp works, in this i have an internal table and only one field,
the field contains a string, I want to check if there is an '=' at the end of the string then delete that records from internal table.
now I have tested '[=]$', '(=)$', '\=$', '=$', but none these seems to work, in the string there can be space between words, please help me with this.
find '=$' in wa_table-field.
if sy-subrc eq 0.
delete i_table.
endif.
04-27-2020 4:14 PM
Hey there,
aren't you missing the "REGEX" in your statement (?) - like:
FIND REGEX 'yourregexhere' IN variable.
Regex Example on RegExr: https://regexr.com/3gjtt (replace the 'I' with your '=' sign)
If it doesn't matter to you where the equal sign in your field is, you could try to go with "CS" (ABAP Documentation).
If you want to play around a bit, chances are you got the following report to 'toy' around with on your SAP system: https://archive.sap.com/documents/docs/DOC-10291
- DEMO_REGEX_TOY
- DEMO_REGEX
Hope some of this can help you.
Best Regards,
Marco
04-27-2020 4:14 PM
Hey there,
aren't you missing the "REGEX" in your statement (?) - like:
FIND REGEX 'yourregexhere' IN variable.
Regex Example on RegExr: https://regexr.com/3gjtt (replace the 'I' with your '=' sign)
If it doesn't matter to you where the equal sign in your field is, you could try to go with "CS" (ABAP Documentation).
If you want to play around a bit, chances are you got the following report to 'toy' around with on your SAP system: https://archive.sap.com/documents/docs/DOC-10291
- DEMO_REGEX_TOY
- DEMO_REGEX
Hope some of this can help you.
Best Regards,
Marco
04-27-2020 4:24 PM
Hi,
try it with the following expression:
FIND REGEX '.*\=$' IN wa_table-field.
Best Regards
Arne
04-27-2020 6:54 PM
can you please explain the need for .*? as I understand that '\' means mandatory..
04-27-2020 8:35 PM
04-27-2020 5:40 PM
Use the SE38 report DEMO_REGEX_TOY to test your REGEX expressions on various test data, so you dont have to do that in debugger, in case you are unsure of the regex syntax and want to try it out and make sure it works.
" With your expression, you are not looking for a regular expression
" But instead, you are looking for exactly the character combination =$
FIND '=$' IN wa_table-field.
" If you type REGEX before your expression, you get what you are looking for
FIND REGEX '=$' IN wa_table-field.
" With the example of Arne Bücker, the result for FIND is the 'same' (sy-subrc = 0)
" However for REPLACE it would be different:
" As yours really finds the = at the EOL, whereas Arne's finds the entire line till the = at the EOL
" (see above screenshot with both examples in the report Regex Toy)
FIND REGEX '.*\=$' IN wa_table-field.
04-27-2020 6:52 PM
05-13-2020 4:45 PM
am3en99, please follow up on your open question.