Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / March 2008

Tip: Looking for answers? Try searching our database.

Help with a regex pattern please

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
be_675@hotmail.com - 21 Mar 2008 00:55 GMT
I have three individual sPattern's that I am working on.  How can I
merge them together so that the pattern will look for three digits
followed by either a period, or by a space and a period, or by a space
and a letter?

Thanks

Const sPattern As String = "d{1,3}(?=\.)"
Const sPattern As String = "d{1,3}[\ ][\.]"
Const sPattern As String = "d{1,3}[\ ][?=\A-Z,a-z]"

Set oRegex = New RegExp
oRegex.Pattern = sPattern
oRegex.Global = True

If oRegex.Test(strIn) = True Then
   Set colMatches = oRegex.Execute(strIn)
   strData = colMatches(0)
End If
Dick Kusleika - 21 Mar 2008 21:15 GMT
>I have three individual sPattern's that I am working on.  How can I
>merge them together so that the pattern will look for three digits
[quoted text clipped - 4 lines]
>Const sPattern As String = "d{1,3}[\ ][\.]"
>Const sPattern As String = "d{1,3}[\ ][?=\A-Z,a-z]"

Const sPattern As String = "\d{1,3}((\.)|(\ \.)|(\ [A-Z,a-z]))"

You have some optional arguments (I think, I don't recognize the syntax)
that I've removed.  This just uses the pipe to separate the three choices.
Signature

Dick Kusleika
Microsoft MVP-Excel
http://www.dailydoseofexcel.com

be_675@hotmail.com - 21 Mar 2008 22:35 GMT
Thank you Dick.  I'm very new to using Regex.  You comments helped.
Ron Rosenfeld - 22 Mar 2008 01:14 GMT
>I have three individual sPattern's that I am working on.  How can I
>merge them together so that the pattern will look for three digits
[quoted text clipped - 15 lines]
>    strData = colMatches(0)
>End If

Your examples do not match your description in several aspects:

Your description says you are looking for **three** digits;

Assuming the "\" should be before the "d", your examples will match 1, 2 or 3
digits.

In your first example, you are using a positive lookahead assertion which means
you will only match the digits, and not the subsequent period.

In your second example, you don't use the positive lookahead assertion, so the
subsequent <space dot> will be matched also.  This seems inconsistent.  And
also, enclosing the <space> and the <.> within a character class is
unnecessary.

Finally your third pattern, in the area following the digits, matches a
<space>, but the subsequent series within the character class do not make up a
legitimate pattern, because the backslash cannot be followed by an "A" when
within a character class.  Also, note that you have a <comma> within the
character class, so you would be also matching a <comma>, which is not
something you stated in your description

Going by your description, if you want to match a series of three digits,
followed by one of those three sequences you describe, then:

"\d{3}(\.|\s\.|\s[A-Za-z])"

or, if you want to match ONLY the digits, provided they are followed by one of
those other three sequences, then:

"\d{3}(?=\.|\s\.|\s[A-Za-z])"

--ron
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.