I have the following XML String:
String XML = "<TEST><MESSAGEID>5435646578</MESSAGEID></TEST>";
The number in the xml string keeps changing so I want to do a string replace and want to make the XML into
<TEST><MESSAGEID></MESSAGEID></TEST>
I am looking for doing something like this but I'm not sure how to get the pattern for the first argument in the replaceAll method.
public class HelloWorld {
public static void main(String[] args) {
String XML = "<MESSAGEID>5435646578</MESSAGEID>";
String newStr = XML.replaceAll("<MESSAGEID>*</MESSAGEID>", "<MESSAGEID></MESSAGEID>");
System.out.println(newStr);
}
}
try replacing your *
in uotmXML.replaceAll("<MESSAGEID>*</MESSAGEID>", ...
with [^<]+
. This will match everything until the <
character