Search code examples
c#regexstring

Detect if a string contains uppercase characters


Is there an alternative to using a regular expression to detect if a string contains uppercase characters? Currently I'm using the following regular expression:

Regex.IsMatch(fullUri, "[A-Z]") 

It works fine but I often hear the old adage "If you're using regular expressions you now have two problems".


Solution

  • You can use LINQ:

    fullUri.Any(char.IsUpper);