An obvious way to handle String search and replace is
String s = "This will go over well!";
s = s.replace("go", "not go");
I wonder .. can the same be done using regex package? Are there benefits from using it?
Can something along the lines of s/go/not go/g exist?
Please look at using
String#replaceAll(String regex, String replacement)instead ofString#replace(...)since this uses a regular expression for the first parameter. The String API will tell you more about this. This does give some added flexibility and power but with the price (I believe — I have not profiled this) of slower execution time.I’m not sure I understand what you’re asking here. Can you please clarify this a bit?