Home All Groups Group Topic Archive Search About

Regular Expression class

Author
26 May 2006 7:20 PM
Bryan Dickerson
I'm trying to use a Regular Expression object to validate/find a
City-State-Zip combination in an address field.  The Pattern that I'm using
is : "^(\w)+,\s[A-Za-z][A-Za-z](\s)+[0-9]{5}(-[0-9]{4})?$".  I have also set
IgnoreCase to True.  When I try the Test method on "MEMPHIS, TN 38141" with
this pattern, I get True, but when I try the Test method with the same
pattern on "BRYAN DICKERSON", it also returns True.  Why?

TIA!

--
TFWBWY...A

Author
31 May 2006 8:22 PM
Bryan Dickerson
Did no one see this?  Or is it just a stupid question?

Show quoteHide quote
"Bryan Dickerson" <txprp***@netscape.net> wrote in message
news:uzCXtlPgGHA.2032@TK2MSFTNGP02.phx.gbl...
> I'm trying to use a Regular Expression object to validate/find a
> City-State-Zip combination in an address field.  The Pattern that I'm
> using is : "^(\w)+,\s[A-Za-z][A-Za-z](\s)+[0-9]{5}(-[0-9]{4})?$".  I have
> also set IgnoreCase to True.  When I try the Test method on "MEMPHIS, TN
> 38141" with this pattern, I get True, but when I try the Test method with
> the same pattern on "BRYAN DICKERSON", it also returns True.  Why?
>
> TIA!
>
> --
> TFWBWY...A
>
Author
31 May 2006 8:57 PM
Bob O`Bob
Bryan Dickerson wrote:
> Did no one see this?  Or is it just a stupid question?
>

It's not a VB question.



    Bob
Author
31 May 2006 9:13 PM
Bryan Dickerson
I posted it here, 'cause I'm using it in a VB6 program, but since it's not a
VB question,  please accept my apologies for going off-topic.  It was not
intentional. Can you suggest where I might get an answer?  Perhaps another
MS newsgroup?

Show quoteHide quote
"Bob O`Bob" <filter***@yahoogroups.com> wrote in message
news:ujLzWUPhGHA.1792@TK2MSFTNGP03.phx.gbl...
> Bryan Dickerson wrote:
>> Did no one see this?  Or is it just a stupid question?
>>
>
> It's not a VB question.
>
>
>
> Bob
Author
31 May 2006 10:06 PM
Bookreader
On Wed, 31 May 2006 16:13:31 -0500, "Bryan Dickerson"
<txprp***@netscape.net> wrote:

Show quoteHide quote
>I posted it here, 'cause I'm using it in a VB6 program, but since it's not a
>VB question,  please accept my apologies for going off-topic.  It was not
>intentional. Can you suggest where I might get an answer?  Perhaps another
>MS newsgroup?
>
>"Bob O`Bob" <filter***@yahoogroups.com> wrote in message
>news:ujLzWUPhGHA.1792@TK2MSFTNGP03.phx.gbl...
>> Bryan Dickerson wrote:
>>> Did no one see this?  Or is it just a stupid question?
>>>
>>
>> It's not a VB question.
>>
>>
>>
>> Bob
>
Where did you get the regular expression class?  Did you make it
yourself in VB?

Please let us know and someone will try to help.

Have you gone through a tutorial on regular expressions?  IF not, try
googling for one.

Thanks.
Author
1 Jun 2006 4:39 AM
Jim Carlock
Regular Expressions started out with Unix and then PERL came
along and made great use of them.

The following links might help. The Virginia.edu link below, ex-
plains that regular expressions date back as a Unix standard, and
that GREP means Global Regular Expression Print. Grep is the
tool used to search through files and suck out text. The asterisk
ends up being used in such searches and initially employed by a
man named Stephen Kleene (and became known as the "Kleene
Star").

http://www.perl.com/pub/a/2006/01/05/parsing.html
http://www.regular-expressions.info/
http://www.regular-expressions.info/tutorial.html
http://etext.lib.virginia.edu/services/helpsheets/unix/regex.html

Hope this helps.

Jim Carlock
Post replies to the group.

"Bookreader" <Bookreader***@yahoo.com> wrote in message news:315s72dju0m8baphqrmf0qeab6q3i0tdj7@4ax.com...
On Wed, 31 May 2006 16:13:31 -0500, "Bryan Dickerson"
<txprp***@netscape.net> wrote:

Show quoteHide quote
>I posted it here, 'cause I'm using it in a VB6 program, but since it's not a
>VB question,  please accept my apologies for going off-topic.  It was not
>intentional. Can you suggest where I might get an answer?  Perhaps another
>MS newsgroup?
>
>"Bob O`Bob" <filter***@yahoogroups.com> wrote in message
>news:ujLzWUPhGHA.1792@TK2MSFTNGP03.phx.gbl...
>> Bryan Dickerson wrote:
>>> Did no one see this?  Or is it just a stupid question?
>>>
>>
>> It's not a VB question.
>>
>>
>>
>> Bob
>
Where did you get the regular expression class?  Did you make it
yourself in VB?

Please let us know and someone will try to help.

Have you gone through a tutorial on regular expressions?  IF not, try
googling for one.

Thanks.
Author
2 Jun 2006 4:59 PM
Bookreader
Show quote Hide quote
On Thu, 1 Jun 2006 00:39:41 -0400, "Jim Carlock" <anonymous@localhost>
wrote:

>Regular Expressions started out with Unix and then PERL came
>along and made great use of them.
>
>The following links might help. The Virginia.edu link below, ex-
>plains that regular expressions date back as a Unix standard, and
>that GREP means Global Regular Expression Print. Grep is the
>tool used to search through files and suck out text. The asterisk
>ends up being used in such searches and initially employed by a
>man named Stephen Kleene (and became known as the "Kleene
>Star").
>
>http://www.perl.com/pub/a/2006/01/05/parsing.html
>http://www.regular-expressions.info/
>http://www.regular-expressions.info/tutorial.html
>http://etext.lib.virginia.edu/services/helpsheets/unix/regex.html
>
>Hope this helps.
>
>Jim Carlock
>Post replies to the group.
>
>"Bookreader" <Bookreader***@yahoo.com> wrote in message news:315s72dju0m8baphqrmf0qeab6q3i0tdj7@4ax.com...
>On Wed, 31 May 2006 16:13:31 -0500, "Bryan Dickerson"
><txprp***@netscape.net> wrote:
>
>>I posted it here, 'cause I'm using it in a VB6 program, but since it's not a
>>VB question,  please accept my apologies for going off-topic.  It was not
>>intentional. Can you suggest where I might get an answer?  Perhaps another
>>MS newsgroup?
>>
>>"Bob O`Bob" <filter***@yahoogroups.com> wrote in message
>>news:ujLzWUPhGHA.1792@TK2MSFTNGP03.phx.gbl...
>>> Bryan Dickerson wrote:
>>>> Did no one see this?  Or is it just a stupid question?
>>>>
>>>
>>> It's not a VB question.
>>>
>>>
>>>
>>> Bob
>>
>Where did you get the regular expression class?  Did you make it
>yourself in VB?
>
>Please let us know and someone will try to help.
>
>Have you gone through a tutorial on regular expressions?  IF not, try
>googling for one.
>
>Thanks.
>

Jim made a great point about Perl.  I used regulars expressions with
Perl and was not aware of the Regular Expression class that you are
using.

We used Perl to run Oracle scripts on big UNIX systems from a Windows
front end.  Notice that later in this thread someone shows how to
accomplish the same thing with pure VB code.

In case you are interested, there is PERL for windows which you can
find with a Google search.

The main point is that there are many ways to skin a cat.  Find one
that works for you and use that.

To be honest, the best way that worked for me was that I used to sit
beside a guy who was a wizard at Regular Expressions and I was pretty
good at SQL queries and Oracle Procedures.  We helped each other out
and had a great time of it.

The great thing about USENET is that several people contributed to
this discussion and you got some good ideas. 

That's just my 2 dollars' worth and maybe more than you wanted to
hear.

Thanks.
Author
1 Jun 2006 2:55 PM
Bryan Dickerson
I'm using the RegExp class that is included in a VBScript DLL.  If you look
at the available references to add to a project, you will find "Microsoft
VBScript Regular Expressions 5.5", the 'Location' of which is
"c:\windows\system32\vbscript.dll\3".  Does this make it a VB question, yet?

Show quoteHide quote
"Bookreader" <Bookreader***@yahoo.com> wrote in message
news:315s72dju0m8baphqrmf0qeab6q3i0tdj7@4ax.com...
> On Wed, 31 May 2006 16:13:31 -0500, "Bryan Dickerson"
> <txprp***@netscape.net> wrote:
>
>>I posted it here, 'cause I'm using it in a VB6 program, but since it's not
>>a
>>VB question,  please accept my apologies for going off-topic.  It was not
>>intentional. Can you suggest where I might get an answer?  Perhaps another
>>MS newsgroup?
>>
>>"Bob O`Bob" <filter***@yahoogroups.com> wrote in message
>>news:ujLzWUPhGHA.1792@TK2MSFTNGP03.phx.gbl...
>>> Bryan Dickerson wrote:
>>>> Did no one see this?  Or is it just a stupid question?
>>>>
>>>
>>> It's not a VB question.
>>>
>>>
>>>
>>> Bob
>>
> Where did you get the regular expression class?  Did you make it
> yourself in VB?
>
> Please let us know and someone will try to help.
>
> Have you gone through a tutorial on regular expressions?  IF not, try
> googling for one.
>
> Thanks.
Author
2 Jun 2006 12:16 AM
Michael Cole
"Bryan Dickerson" <txprp***@netscape.net> wrote in message
news:%23ImvZuYhGHA.4776@TK2MSFTNGP05.phx.gbl...
> I'm using the RegExp class that is included in a VBScript DLL.  If you
look
> at the available references to add to a project, you will find "Microsoft
> VBScript Regular Expressions 5.5", the 'Location' of which is
> "c:\windows\system32\vbscript.dll\3".  Does this make it a VB question,
yet?

Ah no, that actually makes it a VB Scripting question :-).

microsoft.public.scripting.vbscript


--
Regards,

Michael Cole.
Author
2 Jun 2006 2:18 AM
Jim Carlock
"Bryan Dickerson" <txprp***@netscape.net> wrote:
> I'm using the RegExp class that is included in a VBScript DLL.
> If you look at the available references to add to a project, you
> will find "Microsoft VBScript Regular Expressions 5.5", the
> 'Location' of which is "c:\windows\system32\vbscript.dll\3".
> Does this make it a VB question, yet?

Close enough.

Try the following (watch the word wrap):
mk:@MSITStore:D:\Deploy\Updates\vb\vbscript\script56.chm::/html/e0f50a5f-8a5e-437c-bfa8-8c61beb614a4.htm

It requires the vbScript 5.6 help file, script56.chm:
http://msdn.microsoft.com/downloads/list/webdev.asp

Your expression line...
"^(\w)+,\s[A-Za-z][A-Za-z](\s)+[0-9]{5}(-[0-9]{4})?$"

Should it be something along the lines of:
  "\w+,\s\w+\s\d{5}\-\d{4}"
?

I got these to work at the following link:
\w+\s\w+,\s\w+\s[0-9]{5}
or
(\w+)(\s)(\w+),(\s)(\w+)(\s)([0-9]{5})
http://regexlib.com/RETester.aspx

Had some problems getting the dash to work into it.

Hope this helps some.

Jim Carlock
Post replies to the group.
Author
2 Jun 2006 6:07 AM
Sarith Sutha
Your expression seems to be correct. I've tried the same expressions
with the examples that you have provided.

I've used the following  :

Dim m_objRegExp
Set m_objRegExp = New RegExp
m_objRegExp.Pattern =
"^(\w)+,\s[A-Za-z][A-Za-z](\s)+[0-9]{5}(-[0-9]{4})?$"
m_objRegExp.IgnoreCase = True

MsgBox m_objRegExp.test("MEMPHIS, TN 38141") 'Returns True
MsgBox m_objRegExp.test("BRYAN DICKERSON") 'Returns False

I dont know why its not working for you. Check the logic where you have
used this test method.

Regards,
Sarith Sutha

Bryan Dickerson wrote:

Show quoteHide quote
> I'm using the RegExp class that is included in a VBScript DLL.  If you look
> at the available references to add to a project, you will find "Microsoft
> VBScript Regular Expressions 5.5", the 'Location' of which is
> "c:\windows\system32\vbscript.dll\3".  Does this make it a VB question, yet?
>
> "Bookreader" <Bookreader***@yahoo.com> wrote in message
> news:315s72dju0m8baphqrmf0qeab6q3i0tdj7@4ax.com...
> > On Wed, 31 May 2006 16:13:31 -0500, "Bryan Dickerson"
> > <txprp***@netscape.net> wrote:
> >
> >>I posted it here, 'cause I'm using it in a VB6 program, but since it's not
> >>a
> >>VB question,  please accept my apologies for going off-topic.  It was not
> >>intentional. Can you suggest where I might get an answer?  Perhaps another
> >>MS newsgroup?
> >>
> >>"Bob O`Bob" <filter***@yahoogroups.com> wrote in message
> >>news:ujLzWUPhGHA.1792@TK2MSFTNGP03.phx.gbl...
> >>> Bryan Dickerson wrote:
> >>>> Did no one see this?  Or is it just a stupid question?
> >>>>
> >>>
> >>> It's not a VB question.
> >>>
> >>>
> >>>
> >>> Bob
> >>
> > Where did you get the regular expression class?  Did you make it
> > yourself in VB?
> >
> > Please let us know and someone will try to help.
> >
> > Have you gone through a tutorial on regular expressions?  IF not, try
> > googling for one.
> >
> > Thanks.
Author
2 Jun 2006 7:07 AM
Bob O`Bob
Bryan Dickerson wrote:
> I'm using the RegExp class that is included in a VBScript DLL.  If you look
> at the available references to add to a project, you will find "Microsoft
> VBScript Regular Expressions 5.5", the 'Location' of which is
> "c:\windows\system32\vbscript.dll\3".  Does this make it a VB question, yet?

like the folks in the vbscript group said, I don't see the same results.

You also should be aware that some characters not included in /w can definitely
occur in city names.  Dash, dot, and space, at least, perhaps apostrophe and more.
While the underscore (acceptable to /w) seems unlikely.


    Bob
Author
2 Jun 2006 7:49 AM
Rick Rothstein
> I'm trying to use a Regular Expression object to validate/find a
> City-State-Zip combination in an address field.  The Pattern that I'm
> using is : "^(\w)+,\s[A-Za-z][A-Za-z](\s)+[0-9]{5}(-[0-9]{4})?$".  I have
> also set IgnoreCase to True.  When I try the Test method on "MEMPHIS, TN
> 38141" with this pattern, I get True, but when I try the Test method with
> the same pattern on "BRYAN DICKERSON", it also returns True.
>    ........<snip>........
> I'm using the RegExp class that is included in a VBScript DLL.  If you
> look at the available references to add to a project, you will find
> "Microsoft VBScript Regular Expressions 5.5", the 'Location' of which is
> "c:\windows\system32\vbscript.dll\3".  Does this make it a VB question,
> yet?

While I know you started in on this question as a Regular Expression
problem, you do realize that you do not have to use a regular expression.
You can always design a VB function to do what you want and then call that.
Below is just such a function that I quickly dummied-up for you; see if it
does what you want. I have provided comments so you can see what my thinking
was as I developed the function. Pay particular attention to the multi-lined
comment as it addresses a possible need to change the test a little bit.

Rick

Function IsCityStateZip(TextIn As String) As Boolean
  Dim City As String
  Dim State As String
  Dim Zip As String
  Dim CommaSpace As Long
  Dim LastSpace As Long
  '  Find the comma-space separating the city from the state-zip part
  CommaSpace = InStr(TextIn, ", ")
  '  Make sure there is a comma-space and that no double spaces exist
  If CommaSpace > 0 And InStr(TextIn, "  ") = 0 Then
    '  Separate the city from the state-zip part
    City = Left$(TextIn, CommaSpace - 1)
    '  Make sure the city is only composed of letters, spaces, dots,
    '  or dashes (for the likes of St. Augustine, Raleigh-Durham)
    '  Not sure what other characters are possible in a town name...
    '  for example, apostrophes (O' Bryan)? Numbers (Rome2)? etc.
    If Not City Like "*[!A-Za-z .-]*" Then
      '  Separate-zip combination out
      State = Mid$(TextIn, CommaSpace + 2)
      '  Find the space separating the state from the zip
      LastSpace = InStr(State, " ")
      '  Make sure it is located in the 3rd position (2-letter state)
      If LastSpace = 3 Then
        '  Split the zip out
        Zip = Mid$(State, LastSpace + 1)
        '  Adjust the State variable (remove the zip part)
        State = Left$(State, 2)
        '  Make sure the state and zip parts are properly formed
        If State Like "[A-Za-z][A-Za-z]" And _
           (Zip Like "#####" Or Zip Like "#####-####") Then
          IsCityStateZip = True
        End If
      End If
    End If
  End If
End Function