Results 1 to 5 of 5
  1. #1
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    regular expression +ve/-ve integers (Word 2000 et

    I'm at a loss. The code below is supposed to test for valid integer strings - a signed or unsigned integer string.
    The code baulks on tests 5 and 6, and I'm sure I've gotten a wrong pattern.
    After browsing the web for an hour and seeing not the light, I plead for help.
    <pre>Function blnNumeric(strIn As String) As Boolean
    Dim RegEx As regExp
    Set RegEx = New regExp
    RegEx.Pattern = "[-+]?[0-9]+$"
    blnNumeric = RegEx.test(strIn)
    End Function
    Sub TESTblnNumeric()
    Debug.Assert True = blnNumeric("0") ' 1
    Debug.Assert True = blnNumeric("19") ' 2
    Debug.Assert True = blnNumeric("-19") ' 3
    Debug.Assert True = blnNumeric("+19") ' 4
    Debug.Assert False = blnNumeric("+-19") ' 5 ?
    Debug.Assert False = blnNumeric("-+19") ' 6 ?
    Debug.Assert False = blnNumeric("a") ' 7
    Debug.Assert True = blnNumeric("16711935") ' 8
    End Sub</pre>


  2. #2
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: regular expression +ve/-ve integers (Word 2000

    I think the pattern you want is:
    <code>RegEx.Pattern = "^[-+]?[0-9]+$"</code>

    otherwise you will match anywhere in the string.
    Regards,
    Rory

    Microsoft MVP - Excel

  3. #3
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: regular expression +ve/-ve integers (Word 2000

    >otherwise you will match anywhere in the string.
    Thanks, Rory, that did the trick!

  4. #4
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: regular expression +ve/-ve integers (Word 2000

    It's geek humour really - use a caret to make it stick! <img src=/S/grin.gif border=0 alt=grin width=15 height=15>
    Regards,
    Rory

    Microsoft MVP - Excel

  5. #5
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: regular expression +ve/-ve integers (Word 2000

    >use a caret to make it stick! <img src=/S/toilet.gif border=0 alt=toilet width=24 height=26>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •