If I do not understand, you can match everything between quotation marks and replacement.
String s = "flag1 == 'hello' and flag2=='hello2'"; s = s.replaceAll("'([^']+)'", "(\"$1\")"); System.out.println(s); // flag1 == ("hello") and flag2==("hello2")
If you want to replace the space around == :
s = s.replaceAll("\\s*==\\s*'([^']+)'", "==(\"$1\")");
source share