Regex to replace all string literals in a Java file
In my program I will be reading a java file line by line, and if there is
any string literal in that line, i will replace it with (say) "ABC".
Is there any regex to do so?
Ex. If the Java file passed to my program is:
public class TestClass {
private static final boolean isNotThis = false;
public static void main(String[] args) {
String x = "This is a test String";
dummyMethodCall();
if(isNotThis){
makeItThat();
System.out.println("work is done");
}
}
}
Then the output java file should be:
public class TestClass {
private static final boolean isNotThis = false;
public static void main(String[] args) {
String x = "ABC";
dummyMethodCall();
if(isNotThis){
makeItThat();
System.out.println("ABC");
}
}
}
I am willing to know the regex that will help me to detect all string
literals and replace them with a particular string of my choice.
No comments:
Post a Comment