Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Help with a regex pattern please

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
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Help with a regex pattern please

Thank you Dick. I'm very new to using Regex. You comments helped.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,651
Default Help with a regex pattern please

On Thu, 20 Mar 2008 16:55:57 -0700 (PDT), wrote:

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


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
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with a Regex Pattern [email protected] Excel Programming 11 April 30th 07 01:49 AM
Regex techniques Dave Runyan Excel Programming 5 April 28th 07 12:17 AM
RegEx to parse something like this... R Avery Excel Programming 2 March 7th 05 06:41 PM
RegEx in VBE code editor R Avery Excel Programming 6 December 21st 04 01:58 PM
Regex Question William Barnes Excel Programming 5 January 2nd 04 11:57 AM


All times are GMT +1. The time now is 08:48 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"