I have a string that contains source code of an other groovy file in the following format.
def str = "def testcaseObject{
var1: "abc" ,
var2: obj.map['abc'] ,
var3: "xyz" ,
var4: obj.get(0) ,
var5: obj.random() ,
....... "
Within the source file, some of the attributes are strings by default like abc and xyz and few others are functions like obj.map, obj.get, etc.
I want to make these function calls be considered as a string i.e for all occurrences of strings starting with obj, I would like to insert a double quote before obj and double quote exactly before the comma that ends the line.
In the end I would like the above string to be modified as
def str = "def testcaseObject{
var1: "abc" ,
var2: "obj.map['abc'] ",
var3: "xyz" ,
var4: "obj.get(0) ",
var5: "obj.random() ",
....... "
How can I achieve this using a simple replaceAll method using regular expressions in groovy?