Reputation: 12405
I have a java file which I got from android, this has some hard coded values in it. Basically we have a file which creates an object of type country and adds it to a list.
I wish to attain the same functionality but I am not sure of the reg-ex required to find and replace the file contents. Basically this is how one of the lines in it looks like...
countries.add(new Country("af", "Afghanistan", 93));
And this is what I wan't it to look like
[countries addObject:[[Country alloc] initWithArray:@[@"af",@"Afghanistan",@"93"]];
Do you think regex can be used for such extensive case..? Or will I have to manually do this for every entry..?
Upvotes: 1
Views: 1563
Reputation:
You can do a literal search and capture groups like this and replace them.
Regex: countries\.add\(new Country\("([a-z]+)", "(.*)", (\d+)\)\);
Replacement to do: [countries addObject:[[Country alloc] initWithArray:@[@"$1",@"$2",@"$3"]];
Upvotes: 5