Re: Help with a regex pattern please



On Thu, 20 Mar 2008 16:55:57 -0700 (PDT), be_675@xxxxxxxxxxx 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
.



Relevant Pages

  • Re: Pattern Match
    ... I believe that the pattern Doug sent works. ... I have to find 3 digits followed by space and then 2 digits. ... wouldn't have thought possible; improve on PERL5 regexps! ... Jesse Houwing ...
    (microsoft.public.dotnet.languages.csharp)
  • modulo encrypt problem
    ... I am trying to get an extremely simple character string encryption function ... The pattern to be encrypted is a string of ASCII numeric digits. ...
    (comp.lang.c)
  • Re: Entropy in crystalization: up or down?
    ... Strings of digits without context are without ... have short and long blips, as in a Morse Code-type pattern, and these ... any string of digits in pi will be found within any ... artifact behind such patterns. ...
    (talk.origins)
  • Re: Trouble with $key to HASH when Numeric
    ... the end of a string -- in other words, this pattern will always match ... and capture either 5 digits or nothing; 2) the pattern is anchored to ... modifier, which you do not). ...
    (comp.lang.perl)
  • Re: Random?
    ... chosen number that follows a certain pattern (and there is ... The digits of pi are considered *randomish* in that they exhibit ... rest of you didn't have the lateral thinking skills. ... my keyboard. ...
    (sci.math)