RegEX question - Alpha only upper case only.

Shortmeister1

Board Regular
Joined
Feb 19, 2008
Messages
207
Office Version
  1. 365
  2. 2016
  3. 2013
  4. 2010
  5. 2007
  6. 2003 or older
Platform
  1. Windows
Hi

<code style="margin: 0px; padding: 1px 5px; border: 0px; font-variant-numeric: inherit; font-stretch: inherit; line-height: inherit; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; vertical-align: baseline; background-color: rgb(239, 240, 241); white-space: pre-wrap; color: rgb(36, 39, 41);">"[A-Z]*"</code>

To my understanding, this should mean alpha only so that "BOB" would be True and "Bob" would be False.

It's not working of course! Am I missing something important?

Code:
Sub test1()Dim str As String
Dim regEx As New RegExp
Dim blnTest As Boolean


With regEx
    .IgnoreCase = False
    .Pattern = "[A-Z]*"
End With


str = "Bob"
blnTest = regEx.test(str)
Debug.Print str & vbTab & blnTest


Set regEx = Nothing

End Sub

 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Try this as your pattern, because you need to match the whole string:

.Pattern = "^[A-Z]+$"
 
Upvote 0
Although another way to do this is to compare to the Ucase version of the string:

Sub test2()
Dim str As String
str = "Bob"
Debug.Print str = UCase(str)
End Sub
 
Last edited:
Upvote 0
Thanks Scott

UCase is "money for old rope" really. Appreciated though.

I think what I'm trying to do is to improve my knowledge of REGEX which for something so simple is quite complicated!

So "^[A-Z]+$"

Could you unpack this for me. what does "^", "+" and "$" stand for?

Thanks for your help
Martin
 
Upvote 0
Upvote 0
As I have used it here. ^ means start of string. $ means end of string. + means 1 or more characters, it differs from * because that means 0 or more characters.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,176
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top