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: 

Using regexp in abap

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.
1 ACCEPTED SOLUTION

wridgeu
Participant

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

7 REPLIES 7

wridgeu
Participant

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

arne_b1
Explorer
0 Kudos

Hi,

try it with the following expression:

FIND REGEX '.*\=$' IN wa_table-field.

Best Regards

Arne

0 Kudos

can you please explain the need for .*? as I understand that '\' means mandatory..

am3en99 Michael has explained .* in his answer(NB: \ doesn't mean mandatory, it's just an escape character which means that the next character is to be interpreted as a raw character, but it's useless because = is not a special character so it doesn't need to be escaped; \* is a good example of \ use because * is a special character)Please read the regex documentations, especially in the ABAP documentation.

michael_piesche
Active Contributor

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.

0 Kudos

it is find regex '=$' in ....

michael_piesche
Active Contributor
0 Kudos

am3en99, please follow up on your open question.

  • comment answers or your question if there are still open issues.
  • otherwise mark an answer as accepted if it helped you solve your problem
  • or post an answer of yourself and accept it if you found another useful solution yourself
  • or redirect your question to another question that is related and was useful to solve your problem
  • in the end, close your question