Reputation: 3367
Is there any way when using .net's Regex.Match() to work out if a string only contains capitals?
I am working in an application (so I don't have access to the code) which allows me to see if a field matches a certain regex pattern (using Regex.Match() behind the scene). So I want to use this to work out if the string is only capitals.
Thanks!
Upvotes: 4
Views: 13302
Reputation: 70732
You can use the following regex. This will match any uppercase letter that has a lowercase variant.
^\p{Lu}+$
Or you can simply match only uppercase letter characters.
^[A-Z]+$
Upvotes: 6
Reputation: 2376
Use this as your match string for only capital letters and no special characters, including space.
^[A-Z]*$
To allow for special characters(only contains characters not lower case):
^[^a-z]*$
Upvotes: 5