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: 

REPLACE ALL OCCURRENCES OF REGEX

former_member229310
Active Participant
0 Kudos

Hello,  Below statement is not working in my program.   REPLACE ALL OCCURRENCES OF REGEX '[!@#$%^&*+-= ]' IN wa_var1 WITH '_'.   eg :  wa_var1 = 3-ROW SEAT   then output should have been 3_ROW_SEAT  but instead the Output is giving as __ROW_SEAT.    This statement used work before all of a sudden this statement is acting weird in our program.   Could anyone please provide your inputs.  Thanks....

2 REPLIES 2

Former Member
0 Kudos

HI Harsha,

REPLACE ALL OCCURRENCES OF REGEX working fine for me, check the below mentioned piece of code . Its giving desired output. Better you can check your Data declaration of your  variable wa_var1.

If its not resolved , kindly paste your code here. Try to fix the actual bug.

Data : var type string value 'a_b_c_'.

  REPLACE ALL OCCURRENCES OF REGEX   '_'  IN var WITH 'x'.

write : / var .

o/p is axbxcx .

Regards,

Saravana.S


SuhaSaha
Advisor
Advisor
0 Kudos

Hello Harsha,

I'm not sure why you RegEx is behaving this way, but i think this might be due to the special characters - '$', '*', '^' etc. Read the documentation on:

Special Characters in Regular Expressions.

You can use the following code as a replacement to yours:

DATA: v_txt TYPE string VALUE `3-ROW SEAT`.

REPLACE ALL OCCURRENCES OF REGEX '[[:punct:][:space:]]' IN v_txt WITH '_'.

WRITE: / v_txt.