CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    Join Date
    Mar 2007
    Posts
    144

    VB Regular Expression Help

    Trying to get something like so

    Where the following is allowed

    0-100.#######

    where before the decimal 0 to 100 is allowed and after the decimal always 6 digits of any number.

    I was trying something like this, but I am definitely not any good with RegEx

    Code:
    Like ("^([0-9]|[1-9][0-9]|[1-0][0-0][0-0])\.(######)$")
    Any help would be great
    Last edited by versacestl; August 17th, 2010 at 04:07 PM.

  2. #2
    Join Date
    Mar 2007
    Posts
    144

    Re: VB Regular Expression Help

    I thought I had it, and when i put it through Espresso the expression works just fine, but when using it in the following way in a VBscript in VS2005 SSIS, it doesn't work.

    Code:
    Boolean = Variable Like ("^([0-9]|[1-9][0-9]|[1-1][0-0][0-0])\.[0-9][0-9][0-9][0-9][0-9][0-9]$")
    Any thoughts?
    Last edited by versacestl; August 17th, 2010 at 05:51 PM.

  3. #3
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: VB Regular Expression Help

    Where Digits is the name of your field, and MyData is your data file:

    Code:
    Select * from MyData Where  Digits Like "^([0-9]|[1-9][0-9]|[1-1][0-0][0-0])\.[0-9][0-9][0-9][0-9][0-9][0-9]$"
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  4. #4
    Join Date
    Mar 2007
    Posts
    144

    Re: VB Regular Expression Help

    Quote Originally Posted by dglienna View Post
    Where Digits is the name of your field, and MyData is your data file:

    Code:
    Select * from MyData Where  Digits Like "^([0-9]|[1-9][0-9]|[1-1][0-0][0-0])\.[0-9][0-9][0-9][0-9][0-9][0-9]$"
    I am using a flat file to pull in all the rows and the Variable is the Row.Variable that is being checked to mark the boolean to flag the row if its not a proper format.

    The RegEx isn't working because i am getting all the valid rows back, yet the expression works just fine in Espresso and is valid. Is this not a proper expression for VB scripting?

  5. #5
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: VB Regular Expression Help

    Here's how I have done it before:

    Code:
    Option Explicit
    ' Add a reference to Microsoft VBScript Regular Expressions 5.5
    
    Private Sub Form_Load()
    ' Search all the words in a string
      MsgBox validateEmail("[email protected]")
    End Sub
    
    Public Function validateEmail(sEmail As String) As Boolean
        Dim emailExp As RegExp
        Set emailExp = New RegExp
        emailExp.Pattern = "^(\w+\.)*(\w+)@(\w+\.)+([a-zA-Z]{2,4})$"
        If emailExp.Test(sEmail) = True Then
            validateEmail = True
        Else
            validateEmail = False
        End If
    End Function
    
    Private Sub cmdReplace_Click()
        Dim re As RegExp
        Dim result As String
        
        Set re = New RegExp
        re.Global = True
        re.Pattern = ",|\.|(\s+LLC)|(\s+Inc)|(\s+$)"
        result = re.Replace("Joan R. Platt LLC ", "")
        re.Pattern = "\s+"
        Debug.Print re.Replace(result, "|")
        ' "Joan|R|Platt"
    End Sub
    First, says FALSE, then Validates spaces with |
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  6. #6
    Join Date
    Aug 2010
    Posts
    9

    Re: VB Regular Expression Help

    It's been a while since I've GREP'd. I'm not sure what your row looks like but having ranges defined as [0-0] looks a little strange to me. What about something like:

    [/d]?[/d]?[/d].[/d][/d][/d][/d][/d][/d]

    that should retrieve anything with 1-3 digits to the left of the decimal and 6 digits to the right. Only the first two digits are optional, the rest are required.

    LEN

  7. #7
    Join Date
    Mar 2007
    Posts
    144

    Re: VB Regular Expression Help

    Quote Originally Posted by Slug View Post
    It's been a while since I've GREP'd. I'm not sure what your row looks like but having ranges defined as [0-0] looks a little strange to me. What about something like:

    [/d]?[/d]?[/d].[/d][/d][/d][/d][/d][/d]

    that should retrieve anything with 1-3 digits to the left of the decimal and 6 digits to the right. Only the first two digits are optional, the rest are required.

    LEN
    I am using this in VS 2005 SSIS VB Scripting.. So, I would assume either way should work. I will give this one a try, and let you know.

  8. #8
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: VB Regular Expression Help

    VS2005 or Scripting? Wrong forum anyways, it sounds like
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  9. #9
    Join Date
    Mar 2007
    Posts
    144

    Re: VB Regular Expression Help

    Quote Originally Posted by dglienna View Post
    VS2005 or Scripting? Wrong forum anyways, it sounds like
    Integration Services in VS 2005 in uses (Visual Basic) for scripting.
    Last edited by versacestl; August 18th, 2010 at 03:15 PM.

  10. #10
    Join Date
    Aug 2010
    Posts
    9

    Re: VB Regular Expression Help

    OOPS. I guess I forgot a backslash:

    [/d]?[/d]?[/d]\.[/d][/d][/d][/d][/d][/d]

    Just out of curiosity: What's the pipe character for in your expression? I know I'm out of date but I've never seen that before.

  11. #11
    Join Date
    Mar 2007
    Posts
    144

    Re: VB Regular Expression Help

    Quote Originally Posted by Slug View Post
    OOPS. I guess I forgot a backslash:

    [/d]?[/d]?[/d]\.[/d][/d][/d][/d][/d][/d]

    Just out of curiosity: What's the pipe character for in your expression? I know I'm out of date but I've never seen that before.
    The '|' Character causes the regex engine to match either the part on the left side, or the part on the right side. Can be strung together into a series of options.
    Last edited by versacestl; August 19th, 2010 at 08:22 AM.

  12. #12
    Join Date
    Mar 2007
    Posts
    144

    Re: VB Regular Expression Help

    Quote Originally Posted by Slug View Post
    OOPS. I guess I forgot a backslash:

    [/d]?[/d]?[/d]\.[/d][/d][/d][/d][/d][/d]

    Just out of curiosity: What's the pipe character for in your expression? I know I'm out of date but I've never seen that before.
    The expression must be formatted as so

    Code:
    [\d]?[\d]?[\d]\.[\d][\d][\d][\d][\d][\d]
    This also allows 0's to pad the first two digits if they are there which I can NOT have.

    Example:
    004.123456
    019.123456

    I am going to try this also, but if this doesn't work, i am assuming that VB Scripting in SSIS doesn't like the format for some reason.?

    Code:
    ^([0-9]|[1-9][0-9]|100)\.[\d][\d][\d][\d][\d][\d]
    Last edited by versacestl; August 19th, 2010 at 08:27 AM.

  13. #13
    Join Date
    Mar 2007
    Posts
    144

    Re: VB Regular Expression Help

    I just realized this is Microsoft Visual Basic .NET not 6.0..
    I will post a link to this in that section.

  14. #14
    Join Date
    Mar 2007
    Posts
    144

    Re: VB Regular Expression Help

    I just tried

    Code:
           Dim WeightFactor As New Regex("^([0-9]|[1-9][0-9]|100)\.[\d][\d][\d][\d][\d][\d]")
            validWeightFactor = WeightFactor.IsMatch(Row.WEIGHTFACTOR)
    and it seems to work, which the method below does not.

    Code:
    validWeightFactor = Row.WEIGHTFACTOR Like ("^([0-9]|[1-9][0-9]|100)\.[\d][\d][\d][\d][\d][\d]")
    Last edited by versacestl; August 19th, 2010 at 09:26 AM.

  15. #15
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: VB Regular Expression Help

    Like has nothing to do with RegExp. Like is for lists and tables
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

Page 1 of 2 12 LastLast

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured