Regex pattern match

L

larry

I'm having trouble with a pattern match expression using
regex.

I need to have the first 4 characters as letters and the
next 2 characters as digits.
ex... PROJ12 - when trying "\D{4}\d{2}" as the
expression string.. it does not work on the .ismatch
function when i enter "proj12" into a text box.

What is the problem here?

Dim expressinvoice As New Regex("R-\d{3}\D{3,4}")
Dim expressvend As New Regex("^\D{4}\d{2}$")
Dim expressent As New Regex("\d{4}")

Dim svend As String
Dim sinv As String
Dim sent As String

sent = Trim(txtent.Text)
svend = Trim(txtvend.Text)
sinv = Trim(txtinvoice.Text)

If Not expressent.IsMatch(sent) Then
MsgBox("entity does not match format")

Exit Sub
End If


If expressvend.IsMatch(svend) Then

MsgBox("vendor is not a match")

Exit Sub
ElseIf expressinvoice.IsMatch(sinv) Then

MsgBox("invoice does not match format")
Exit Sub
End If
 
J

Jay B. Harlow [MVP - Outlook]

Larry,
The following works:
Dim expressvend As New Regex("^\D{4}\d{2}$")
Dim svend As String

svend = "proj12"
If Not expressvend.IsMatch(svend) Then

MsgBox("vendor is not a match")

Exit Sub
End If

Note you are missing the "Not" on the expressvend.IsMatch expression.

Hope this helps
Jay
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top