Tim's right, you can test the regex beforehand - my students like https://regex101.com/ for testing regular expressions online. A regex checker like that can help, especially if you're new to regular expressions.
Could you perhaps post the regular expression you were attempting to use? Regular expressions are powerful, and with much power... you probably know the rest.
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.
Bjoke: A "Bully Joke". A Statement or action made with malicious intent - unless challenged. At which point it magically transforms into "I was just funnin'" or "What's the matter, can't take a joke?"
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop