Search code examples
regexvbscriptregistry

How to match jre1.5.0_14 via regex?


I am trying to search all the registry keys and check the data if there is any jre1.5.0_14. I wonder how can I match jre1.5.0_14 via regex?

Thanks in advance.

Best Regards.


Solution

  • There is no point in using regular expressions when you're looking for a particular (sub)string. String functions provide better performance in that scenario:

    If InStr(str, "jre1.5.0_14") > 0 Then
      'do something
    End If
    

    Regular expressions are useful when you want to match a variety of (sub)strings, for instance JRE 1.5 updates 14 through 17:

    Set re = New RegExp
    re.Pattern = "jre1.5.0_1[4-7]"
    
    If re.Test(str) Then
      'do something
    End If