If alph to numberic in regex

I want to check to see if my first five string is alpha and the next five is numberic using Regex.
ABCDE12345
VBdotnet2005Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Terry WoodsIT GuruCommented:
Use pattern:
^[A-Z]{5}\d{5}$
0
sjklein42Commented:
This should do it:

[A-Z]{5}[0-9]{5}

Open in new window

0
Terry WoodsIT GuruCommented:
In code I think it goes something like this...

If Regex.Match(str, "^[A-Z]{5}\\d{5}$").Success Then
     strErr = "Error!"
End If
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

Terry WoodsIT GuruCommented:
Oops, that would be:

If Regex.Match(str, "^[A-Z]{5}\\d{5}$").Success Then
     strMsg = "Great!"
End If
0
sjklein42Commented:
My solution was missing the leading ^ to anchor the search at the start of the string.  @TerryAtOpus got it right.

You only need the "$" at the end of the pattern if you do not want any characters to be allowed after the five digits.  (That was not in your problem description.)

^[A-Z]{5}[0-9]{5}

Open in new window

0
VBdotnet2005Author Commented:
I can use this, correct? I am not sure what this does  regexoptions.complied?
private reg_str as new regex("^[A-Z]{5}[0-9]{5}$", regexoptions.complied)

if reg_str.ismatch(mystring) then
...
end if
0
VBdotnet2005Author Commented:
^[A-Z]{5}\\d{5}$")  I don't understand this
^[A-Z]{5}[0-9]{5}  , I understand this

sorry, I am new to regex
0
Terry WoodsIT GuruCommented:
\d means a digit. The \ is backslashed because of the way .NET handles strings.
0
Terry WoodsIT GuruCommented:
(so \\d and [0-9] are the same thing)
0
Terry WoodsIT GuruCommented:
As for the question about regexoptions, you might like to use something like this if you want to ignore case:

Dim options As RegexOptions = RegexOptions.IgnoreCase
If Regex.Match(str, "^[A-Z]{5}\\d{5}$").Success Then
     strMsg = "Great!"
End If
0
Terry WoodsIT GuruCommented:
Sorry, should be:

Dim options As RegexOptions = RegexOptions.IgnoreCase
If Regex.Match(str, "^[A-Z]{5}\\d{5}$", RegexOptions).Success Then
     strMsg = "Great!"
End If
0
Terry WoodsIT GuruCommented:
Note I'm not a VB.NET programmer - my forte is regular expressions (which are pretty similar across languages). The code I provide is based on other answers so might be a little buggy!
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.