I'd like to use Regex to ensure that there are at least two upper case characters in a string, in any position, together or not.
The following gives me two together:
([A-Z]){2}
Environment - Classic ASP VB.
I'd like to use Regex to ensure that there are at least two upper case characters in a string, in any position, together or not.
The following gives me two together:
([A-Z]){2}
Environment - Classic ASP VB.
You can use the simple regex
[A-Z].*[A-Z]
which matches an upper case letter, followed by any number of anything (except linefeed), and another uppercase letter.
If you need it to allow linefeeds between the letters, you'll have to set the single line flag. If you're using JavaScript (U should always include flavor/language-tag when asking regex-related questions), it doesn't have that possibility. Then the solution suggested by Wiktor S in a comment to another answer should work.
[A-Z].*[A-Z]
A to Z , any symbols between, again A to Z
update
As Wiktor mentioned in comments:
This regex will check for 2 letters on a line (in most regex flavors), not in a string.
So
[A-Z][^A-Z]*[A-Z]
Should do the thing (In most regex flavors/tools)
I believe what you're looking for is something like this:
.*([A-Z]).*([A-Z]).*
Broken out into segments thats:
.* //Any number of characters (including zero)
([A-Z]) //A capital letter
.* //Any number of characters (including zero)
([A-Z]) //A second capital letter
.* //Any number of characters (including zero)