467,077 Members | 1,037 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,077 developers. It's quick & easy.

Regex pattern match

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
Nov 20 '05 #1
  • viewed: 1260
Share:
1 Reply
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

"larry" <la***@larrymckay.com> wrote in message
news:08****************************@phx.gbl... 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

Nov 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by taylorjonl | last post: by
8 posts views Thread by tomb | last post: by
1 post views Thread by Prabhu Gurumurthy | last post: by
7 posts views Thread by jaylucier@gmail.com | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.