Sulprobil
Search…
Regular Expressions
"It pays to be obvious, especially if you have a reputation for subtlety." [Isaac Asimov]
A regular expression is a string that is used to describe or match a set of strings, according to certain syntax rules. Regular expressions can easily be used to describe complex string filters, to extract or to replace strings or parts of strings.
A useful function which I found in the web:
Please read my Disclaimer.
1
'String replacement with Regular Expressions via vbscript.regexp
2
'Parameters:
3
'SourceString String to look into
4
'Pattern Search pattern
5
'ReplaceString Replacement string, use $i for submatches, i=1,2,...
6
'IgnoreCase Flag whether to ignore capitals
7
'GlobalReplace Flag whether to replace all matches or only first one
8
'MultiLine Flag whether ^ and $ match in each row
9
'
10
'Returns: SourceString with replacement(s) if applicable
11
'
12
Function RegExpReplace(ByVal SourceString As String, _
13
ByVal Pattern As String, ByVal ReplaceString As String, _
14
Optional ByVal IgnoreCase As Boolean = False, _
15
Optional ByVal GlobalReplace As Boolean = False, _
16
Optional ByVal MultiLine As Boolean = False) As String
17
18
Dim objRE As Object
19
20
Set objRE = CreateObject("vbscript.regexp")
21
objRE.Pattern = Pattern
22
objRE.IgnoreCase = IgnoreCase
23
objRE.Global = GlobalReplace
24
objRE.MultiLine = MultiLine
25
RegExpReplace = objRE.Replace(SourceString, ReplaceString)
26
Set objRE = Nothing
27
End Function
Copied!
Last modified 1yr ago
Copy link