INPUT TEXT FROM FILE :
someother block {
enable route yes;
dhcp auto;
....
}
options {
dnssec-enable yes;
dnssec-validation yes;
dnssec-lookaside auto;
.....
}
I would like to replace all the "yes" and "auto" text in options block ONLY with "no" and "manual" respectively.
How can I accomplish this?
Here is my execution but the text is not replaced.
String dataPattern = "\noptions \\{\\s*\n(dnssec-[a-z]+ ([a-z]+));";
Pattern filePattern = Pattern.compile(dataPattern, Pattern.DOTALL);
Matcher filePatternMatcher = filePattern.matcher(input);
if(filePatternMatcher.find()){
System.out.println("0 - "+filePatternMatcher.group(0)); //0 - \ndnssec-enable yes;
System.out.println("1 - "+filePatternMatcher.group(1)); //1 - dnssec-enable yes
System.out.println("2 - "+filePatternMatcher.group(2)); //2 - yes
String value = filePatternMatcher.group(2);
value.replaceAll("\ndnssec-enable ([a-z]+);", "$1somethingelse");
System.out.println("new replaced text:"+value); \\ new-replaced text: yes
}
yes;withno;andauto;withmanual;.yesandautoonly if its within the matchingoptions {block.Matcher.appendReplacement(). FYI: The reason your code is not working, is becauseString.replaceAll()returns the updated value. It does not modify the input string. Read the javadoc!!