Skip to content

Commit 8cc25c8

Browse files
authored
Add files via upload
Changed to category 7 (Text)
1 parent 0539f46 commit 8cc25c8

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

VBComponents/modRegExp.bas

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
Attribute VB_Name = "modRegExp"
2+
Option Explicit
3+
4+
Private Sub AddInMenuProperties()
5+
' Custom function for changing file properties (not used during run time)
6+
ActiveWorkbook.BuiltinDocumentProperties("Title").Value = "Regular Expression Add-In 1.1"
7+
ActiveWorkbook.BuiltinDocumentProperties("Comments").Value = "Regular expression functions from Google Sheets."
8+
End Sub
9+
10+
Public Function REGEXMATCH(text As String, _
11+
regular_expression As String) As Boolean
12+
Attribute REGEXMATCH.VB_Description = "Whether a piece of text matches a regular expression."
13+
Attribute REGEXMATCH.VB_ProcData.VB_Invoke_Func = " \n7"
14+
15+
With CreateObject("VBScript.RegExp")
16+
.Global = True
17+
.MultiLine = True
18+
.IgnoreCase = False 'Case-sensitive
19+
.Pattern = regular_expression
20+
REGEXMATCH = .test(text)
21+
End With
22+
23+
End Function
24+
25+
Public Function REGEXEXTRACT(text As String, _
26+
regular_expression As String) As String
27+
Attribute REGEXEXTRACT.VB_Description = "Extracts matching substrings according to a regular expression."
28+
Attribute REGEXEXTRACT.VB_ProcData.VB_Invoke_Func = " \n7"
29+
30+
With CreateObject("VBScript.RegExp")
31+
.Global = False ' Only first match will be returned
32+
.MultiLine = True
33+
.IgnoreCase = False ' Case-sensitive
34+
.Pattern = regular_expression
35+
REGEXEXTRACT = .Execute(text).Item(0).Value
36+
End With
37+
38+
End Function
39+
40+
Public Function REGEXREPLACE(text As String, _
41+
regular_expression As String, replacement As String) As String
42+
Attribute REGEXREPLACE.VB_Description = "Replaces part of a text string with a different text string using regular expressions."
43+
Attribute REGEXREPLACE.VB_ProcData.VB_Invoke_Func = " \n7"
44+
45+
With CreateObject("VBScript.RegExp")
46+
.Global = True
47+
.MultiLine = True
48+
.IgnoreCase = False ' Case-sensitive
49+
.Pattern = regular_expression
50+
REGEXREPLACE = .Replace(text, replacement)
51+
End With
52+
53+
End Function
54+
55+
Sub RegExpArg()
56+
57+
Application.MacroOptions "REGEXMATCH", "Whether a piece of text matches a regular expression.", , , , , 7, , , , _
58+
Array("The text to be tested against the regular expression.", _
59+
"The regular expression to test the text against.")
60+
61+
Application.MacroOptions "REGEXEXTRACT", "Extracts matching substrings according to a regular expression.", , , , , 7, , , , _
62+
Array("The input text.", _
63+
"The first part of text that matches this expression will be returned.")
64+
65+
Application.MacroOptions "REGEXREPLACE", "Replaces part of a text string with a different text string using regular expressions.", , , , , 7, , , , _
66+
Array("The text, a part of which will be replaced.", _
67+
"The regular expression. All matching instances in text will be replaced.", _
68+
"The text which will be inserted into the original text.")
69+
70+
End Sub

0 commit comments

Comments
 (0)