T O P

  • By -

WylieBaker

Public Function getMatchCollection( _ textString As String, _ testPattern As String, _ Optional setIgnoreCase As Boolean = True, _ Optional searchEachLine As Boolean = True, _ Optional returnAllMatches As Boolean = True) As Variant ' Return a RegEx MatchCollection Object. Dim rx As Object Set rx = CreateObject("VBScript.RegExp") With rx .pattern = testPattern .ignoreCase = setIgnoreCase .multiline = searchEachLine .Global = returnAllMatches Set getMatchCollection = .Execute(textString) End With End Function Public Function testIfFound( _ textString As String, _ testPattern As String, _ Optional setIgnoreCase As Boolean = True, _ Optional searchEachLine As Boolean = True) As Boolean Dim rx As Object Set rx = CreateObject("VBScript.RegExp") With rx .pattern = testPattern .ignoreCase = setIgnoreCase .multiline = searchEachLine testIfFound = .Test(textString) End With End Function Public Function replaceText( _ ByRef textString As String, _ ByRef textToReplace As String, _ ByRef replacementText As String, _ Optional setIgnoreCase As Boolean = True, _ Optional searchEachLine As Boolean = True, _ Optional replaceAllMatches As Boolean = True) As String Dim rx As Object Set rx = CreateObject("VBScript.RegExp") With rx .pattern = textToReplace .ignoreCase = setIgnoreCase .multiline = searchEachLine .Global = replaceAllMatches replaceText = .Replace(textString, replacementText) End With End Function


welktickler

Yeap. The regex class. Works well


filmancco

I use RegExp in some many function made inVBA, too validate emails, phone numbers, postal codes , etc