I was wondering if there might be some reason someone would want to use a regular expression for a problem that could also be written easily without using regular expressions.
I came to this thought because of this question.
The question is something fairly simple, and the answers vary in 2 categories, those who do solve it with regular expressions and those who just use some other simple operation.
Summary of the question:
Remove the first part of a url path (example: String path = "/folder1/folder2/folder3/"
).
2 Solutions:
//With regex
String newPathRegex = path.replaceAll("^/[^/]*", "");
//Without regex
String newPathNoRegex = path.substring(path.indexOf('/', 1));
Personally I think the no RegEx solution is a lot easier to read, but I'm not an expert on regular expressions.
So the question comes down to: Should you avoid using regular expressions in cases as simple as this one? Is there better performance in the RegEx solution?