For simple cases String.Contains
will give you better performance but String.Contains
will not allow you to do complex pattern matching. Use String.Contains
for non-pattern matching scenarios (like the one in your example) and use regular expressions for scenarios in which you need to do more complex pattern matching.
A regular expression has a certain amount of overhead associated with it (expression parsing, compilation, execution, etc.) that a simple method like String.Contains
simply does not have which is why String.Contains
will outperform a regular expression in examples like yours.