My input string is:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><tag1><tag2></tag2></tag1>
I want to replace below part:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><tag1>
with spaces.
So I wrote:
String final = inputString.replaceFirst("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><tag1>", "");
However, its not working.
On printing final to the console, it is still same as inputString.
What is the issue ?
You don’t want to use a regex replacement. Just use the plain simple
replacemethod and the code will work. The string literal you are using will be correct in that case.