In this article we will learn about some of the frequently asked Visual Basic programming questions in technical like “vba regex wildcard” Code Answer. When creating scripts and web applications, error handling is an important part. If your code lacks error checking code, your program may look very unprofessional and you may be open to security risks. Error handling in VBA is simple. An error message with filename, line number and a message describing the error is sent to the browser. This tutorial contains some of the most common error checking methods in Visual Basic. Below are some solution about “vba regex wildcard” Code Answer.
vba regex wildcard
xxxxxxxxxx
1
' Returns true if pSearched matches pPattern with wildcards
2
' Needs reference "Microsoft VBScript Regular Expressions 5.5"
3
Function RegexMatch(ByVal pSearched As String, ByVal pPattern As String, _
4
Optional ByVal pIgnoreCase As Boolean = True) As Boolean
5
Dim rRegex As Object
6
7
Set rRegex = CreateObject("VBScript.RegExp")
8
pPattern = Replace(pPattern, ".", "[.]")
9
pPattern = Replace(pPattern, "*", ".*")
10
pPattern = Replace(pPattern, "?", ".")
11
With rRegex
12
.IgnoreCase = pIgnoreCase
13
.Pattern = pPattern
14
End With
15
RegexMatch = rRegex.test(pSearched)
16
End Function
17
' ------------------------------------------------------------------------
18
Sub TestMe()
19
Debug.Print RegexMatch("helloworld.txt", "*.txt") 'True
20
Debug.Print RegexMatch("helloworld.txt", "hell*o?ld.tx*") 'True
21
Debug.Print RegexMatch("HELLOworld.txt", "hel*.tx*", False) 'False
22
End Sub