0

I have the following XML String:

 <asd1:content></asd1:content>

The namespace prefix asd1 could be different at different places in the XML file.

I want to modify it to :

 <asd1:content>*</asd1:content>

I am trying to do it via regex as follows:

myString.replaceAll("<.*:content></.*:content>","replacement text");

The problem is that I don,t want to lose the namespace prefix. What should I do?

user1107888
  • 1,481
  • 5
  • 34
  • 55

1 Answers1

0

Please note that you've 2 typos:

cotent instead of content
replaceAlll instead of replaceAll

If you still need a regex, you can use:

String resultString = subjectString.replaceAll("(?ism)<(.*?):content></(.*?)\\.content>", "<$1:content>*</$2.content>");
Pedro Lobito
  • 94,083
  • 31
  • 258
  • 268