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".
isUpperCase(char ch) determines if the specified character is an uppercase character. A character is uppercase if its general category type, provided by Character.
Python Isupper() To check if a string is in uppercase, we can use the isupper() method. isupper() checks whether every case-based character in a string is in uppercase, and returns a True or False value depending on the outcome.
IsUpper(String, Int32) Method. This method is used to check whether the specified string at specified position matches with any uppercase letter or not. If it matches then it returns True otherwise returns False.
You can also use a regular expression to explicitly detect uppercase roman alphabetical characters. isUpperCase = function(char) { return !!/[A-Z]/.
You can use LINQ:
fullUri.Any(char.IsUpper);
RegEx seems to be overkill:
bool containsAtLeastOneUppercase = fullUri.Any(char.IsUpper);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With