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

Help With Regular Expression

miguel_motta
Participant
1,858

Hi experts,

I need a regex to use on Replace statement, that clear all xXmlCTe tags on a string.

Originally, string don't have line breaks or spaces between tags.

<xXMLCTe xmlns:ns0="http://www.teste1.com">
	<xXMLCTe xmlns="http://www.teste2.com">
		<cteProc versao="3.00">....</cteProc>
	</xXMLCTe>
</xXMLCTe>

After replace...

<cteProc versao="3.00">....</cteProc>

If syntax is different on java and ABAP, I would appreciate if you could send me both.

Thanks a lot!

1 ACCEPTED SOLUTION
Read only

Sandra_Rossi
Active Contributor
1,606

Something like this regular expression? (run program DEMO_REGEX_TOY)

</?xXMLCTe[^>]*>

? = previous character is optional

[^...] any character which is not one of the characters inside

* repeat previous element zero or any number of times

5 REPLIES 5
Read only

Sandra_Rossi
Active Contributor
1,607

Something like this regular expression? (run program DEMO_REGEX_TOY)

</?xXMLCTe[^>]*>

? = previous character is optional

[^...] any character which is not one of the characters inside

* repeat previous element zero or any number of times

Read only

former_member663017
Participant
1,606

Since he is going to replace the tags, can we only focus on the starting part of the tag with the below regular expression:

<\/?xXMLCTe

It works very similar to what Sandra has mentioned, it will select only the tag name so it might come in handy if you want to keep the attributes.

You can play around in https://regexr.com/ it is really helpful for regex.

Read only

egor_malov
Contributor
1,606

Hi, Miguel,

I would like to note that generally there are tools for XML processing in ABAP, so there is no need to reimplement XML parser/builder. Regexp might be ok for this minor task, but should you have something more complex later - I would recommend to have a look at those tools.

Read only

miguel_motta
Participant
0 Likes
1,606

Thanks for all!

Sandra, your regular expression is exactly what I need.

Accept button is not available for me.

Best regards!

Read only

1,606

I hope you have now one step in regular expressions and can learn more powerful ones by reading the documentation.