Application Development and Automation 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: 
Read only

Removing regEx

Former Member
0 Likes
1,815

Hi,

I have a string in the below format.

<?xml version="1.0" encoding="UTF-8"?>#<Data>##><Row>#####<Entry>Test1</Entry>#####<Entry>Dtest2</Entry>#####<Entry>Test3</Entry>#####<Entry>-</Entry>#####<Entry>-</Entry>#####<.........so on

i wanted this string without '#' as below:

<?xml version="1.0" encoding="UTF-8"?><Data>><Row><Entry>Test1</Entry><Entry>Dtest2</Entry><Entry>Test3</Entry><Entry>-</Entry><Entry>-</Entry><.........so on

I tried using REPLACE ALL OCCURENCES REGEX '[[:punct:]]' for string with ''.

This is removing even the '<' , '>', '/' , etc...[Its resulting only the alphabets and numbers.

Can some one please provide a feasible solution.

Regards,

Rajkamal

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,762
REPLACE ALL OCCURENCES OF REGEX '\Q#\E' IN gv_string WITH ''.

Hi,

I have a string in the below format.

<?xml version="1.0" encoding="UTF-8"?>#<Data>##><Row>#####<Entry>Test1</Entry>#####<Entry>Dtest2</Entry>#####<Entry>Test3</Entry>#####<Entry>-</Entry>#####<Entry>-</Entry>#####<.........so on

i wanted this string without '#' as below:

<?xml version="1.0" encoding="UTF-8"?><Data>><Row><Entry>Test1</Entry><Entry>Dtest2</Entry><Entry>Test3</Entry><Entry>-</Entry><Entry>-</Entry><.........so on

I tried using REPLACE ALL OCCURENCES REGEX '[[:punct:]]' for string with ''.

This is removing even the '<' , '>', '/' , etc...[Its resulting only the alphabets and numbers.

Can some one please provide a feasible solution.

Regards,

Rajkamal

14 REPLIES 14
Read only

Former Member
0 Likes
1,763
REPLACE ALL OCCURENCES OF REGEX '\Q#\E' IN gv_string WITH ''.
Read only

0 Likes
1,762

Hi,Thanks for the response.

The above code did not work

Nothing changes.

Regards,

Rajkamal

Read only

matt
Active Contributor
0 Likes
1,762

Go into debug and tell me the hex value of one of these "#"

Read only

0 Likes
1,762

>

> Hi,Thanks for the response.

>

> The above code did not work

>

> Nothing changes.

>

> Regards,

> Rajkamal

Already had a feeling this would be your reply.

Do as Matt requested.

Read only

0 Likes
1,762

Hi Matt,

Here is the hex value for '#' 0023.

Regards,

Rajkamal

Read only

matt
Active Contributor
0 Likes
1,762

That's good. So it really is a '#'.

You could use the non-regex REPLACE ALL OCCURENCES OF '#' IN my_string WITH space. And then use CONDENSE NO-GAPS.

Regex for me has always been trial and error, using the online tutorial and online test tools, which you can find with google.

Read only

0 Likes
1,762

Funny enough it does work for me then.

Read only

0 Likes
1,762

Oh no! Even this is not working for me!

I would like to explain my scenario a bit brief .

I am calling a URL using web service. The methods called for this are : CALL METHOD http_client->send , CALL METHOD http_client->receive

Then storing the received data as: result = http_client->response->get_cdata( ). [This is resulting in as XML with '#' as mentioned above].

Regards,

Rajkamal

Read only

0 Likes
1,762

Is the result an internal table? A single variable? What's the type definition?

Read only

0 Likes
1,762

The result is a variable.

result TYPE string

Read only

0 Likes
1,762
data: gv_string type string.

gv_string = '<?xml version="1.0" encoding="UTF-8"?>#<Data>##><Row>#####<Entry>Test1</Entry>#####<Entry>Dtest2</Entry>#####<Entry>Test3</Entry>#####<Entry>-</Entry>#####<Entry>-</Entry>#####<.........>'.

write: / gv_string.
REPLACE ALL OCCURENCES OF REGEX '\Q#\E' IN gv_string WITH ''.
write: / gv_string.

My example that worked.

Read only

0 Likes
1,762

Yes, the above code worked for me as well. Is it like the hard-coded values accept the statement REPLACE ALL OCCURENCES OF REGEX '\Q#\E' IN gv_string WITH '', but not the string which we get dynamically?

Read only

0 Likes
1,762

Hi Matt/Maen,

The issue is resolved. The string with #### is not exactly'#' value, but they are actually representing horizontal tab and new line.

To overcome this, i used :

REPLACE ALL OCCURRENCES OF SUBSTRING cl_abap_char_utilities=>horizontal_tab IN result WITH ''.

REPLACE ALL OCCURRENCES OF SUBSTRING cl_abap_char_utilities=>newline IN result WITH ''.

Thanks for your time.

Regards,

Rajkamal

Read only

matt
Active Contributor
0 Likes
1,762

So the hex value of the # in your input string wasn't x0023. Which is what we suspected in the first place!