regex VS Contains. Best Performance?

java, regex

Solution

They're both fast enough to be over before you know it. I'd go for the one that you can read more easily.

Problem

I want to compare an URI String over different patterns in java and I want fastest code possible. Should I use : ``` if(uri.contains("/br/fab") || uri.contains("/br/err") || uri.contains("/br/sts") ``` Or something like : ``` if(uri.matches(".*/br/(fab|err|sts).*")) ``` Note that I can have a lot more uri and this method is called very often. What is the best answer between my choices ?

Original source

Related problems