Results 1 to 2 of 2

Thread: [RESOLVED] RegEx in VBA

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2008
    Posts
    267

    Resolved [RESOLVED] RegEx in VBA

    Code:
    Dim RegEx As Object
    Dim valid As String
    Set RegEx = CreateObject("vbscript.regexp")
    RegEx.Pattern = " \d{10}"
    valid = RegEx.Replace("this is a test 1234567895 for real", "")
    MsgBox (valid)
    This work fine .. only problem is that i dont need to strip the 10 digits, but i need that value of 10 digits.. With what command should i replace 'Replace' with?

    valid is now: "this is a test for real"
    i need: value = "1234567895"

  2. #2

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2008
    Posts
    267

    Re: RegEx in VBA

    nm

    Code:
    Dim RegEx As Object
    Dim RegMatches As Object
    Set RegEx = CreateObject("vbscript.regexp")
        With RegEx
            .MultiLine = False
            .Global = False
            .IgnoreCase = True
            .Pattern = " \d{10}"
        End With
    
    Set RegMatches = RegEx.Execute("this is a test 1234567895 for real")
    MsgBox (RegMatches(0))

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