I have a file, typically XML files. I want to replace all the occurrences of 'x.y' with 'p.q'. But during this replacement, i want to ignore the occurrences of x.y in comments ().
I was trying to use String.replaceAll() to perform this task.
For Example :
<?xml version="1.0" encoding="UTF-8"?>
<name>This occurrence of x.y should be replaced</name>
<!-- This occurrence of x.y should not be replaced -->
I tried using String.replaceAll("x[\.]y", "p.q") but i could see that occurrences in comments are also getting replaced
I could use an other alternative by which i can read the file line by line and exclude the lines that starts with comments, but i am interested in using replaceAll()
Please provide a way by which this can be achieved.