Regular Expressions

You can add an additional Reference
Microsoft VBScript Regular Expressions 5.5
C:\Windows\System32\vbscript.dll
link - learn.microsoft.com/en-us/previous-versions/windows/internet-explorer/ie-developer/scripting-articles/ms974570(v=msdn.10)

Dim sTextString As String 

Dim oRegEx As RegExp
Dim oRegExResults As Object
Set oRegEx = New RegExp
'Set oRegEx = CreateObject("VBScript.RegExp")

oRegEx.Global = True
oRegEx.MultiLine = True
oRegEx.IgnoreCase = False

'replacing text
Dim sNewString As String
sTextString = "bettersolutions"
oRegEx.Pattern = "better"
sNewString = oRegEx.Replace(sTextString, "amazing")
Debug.Print sNewString

'testing for a match, 2 digit numbers
Dim bfound As Boolean
sTextString = "1,2,30,4,5"
oRegEx.Pattern = "\d{2}"
bfound = oRegEx.Test(sTextString)
If (bfound = True) Then
   Debug.Print "match found"
End If

extracting all instances
Dim oFound As Object
sTextString = "one,two,three,four"
oRegEx.Pattern = "[a-z]+"
Set oRegExResults = oRegEx.Execute(sTextString)
For Each oFound In oRegExResults
   Debug.Print oFound
Next oFound

© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext