Question : Using RegExp to Simulate Like

I need to perform a "Like" test on string in a VBScript with patterns that contain * wildcards.  I am sure this can be done with RegExp, but I don't really get how it works.  Can someone advise how to complete this code?

Function IsLike(Value, Pattern)
    Dim RXObject, RXPattern
    Set RXObject = NewRexExp
        With RXObject
            .Global = True
            .IngoreCase = True
            RXPattern =  ......
            .RXPattern = RXPattern
            IsLike = .Test(Value)
        End With
    Set RXObject = Nothing
End Function

Mike

Answer : Using RegExp to Simulate Like

LOoking at like for like:

Function IsLike(Value, Pattern)
Dim regEx
   
    Set regEx = CreateObject("vbscript.regexp")
        With regEx
            .Global = True
            .IgnoreCase = True
            .Pattern = "^" & Replace(Pattern, "*", ".{0,}") & "$"
            IsLike = .Test(Value)
        End With
    Set regEx = Nothing
End Function

Will accept control codes between the strings whereas

Function IsLike(ByVal TextVal, ByVal Pattern)
  Dim RXP
  IsLike = False
  Set RXP = New RegExp
    With RXP
      .Global = True
      .IgnoreCase = True
      .Pattern = "^" & Replace(Pattern, "*", "[\x20-\x7E]*") & "$"
      IsLike = .Test(TextVal)
    End With
  Set RXP = Nothing
End Function

WIll ensure the only characters between the components are alphanumerics and common punctuation.

Chris
Random Solutions  
 
programming4us programming4us