posted 7 years ago
Regexes are compiled into programs for a finite state machine. This is usually very efficient. Basic regexes don't even have the ability to get into a loop - that requires one of the more advanced regex processors and some very specific coding, since the normal action of a regex matcher consumes text and will eventually reach the end of input.
The regex "(.*)/(.*)" didn't look like a problem, and I don't think it was. The second regex "(.*)+(.*)" can actually be treated in one of 2 different ways, depending on whether greedy matching or lazy matching is done. Or, a regex compiler might outright reject it as being ambiguous. In any case, however, it would seen that the regex should have consumed all input and stopped.
So I have to wonder if the loop was actually in the regex line or somewhere else.
In any event, the "contains" method is a lot more straightforward and should be more efficient.
Another approach would be to use the "split()" method and count the number of Strings that was returned, but "contains" works better here.
Education won't help those who are proudly and willfully ignorant. They'll literally rather die before changing.