質問編集履歴

2

2016/09/09 05:28

投稿

piyotaka
piyotaka

スコア39

test CHANGED
File without changes
test CHANGED
File without changes

1

コード例の記載

2016/09/09 05:28

投稿

piyotaka
piyotaka

スコア39

test CHANGED
File without changes
test CHANGED
@@ -1,4 +1,4 @@
1
- VBAと正規表現について勉強している者です。
1
+ ```VBAと正規表現について勉強している者です。
2
2
 
3
3
 
4
4
 
@@ -49,3 +49,57 @@
49
49
 
50
50
 
51
51
  以上,よろしくお願いいたします。
52
+
53
+
54
+
55
+
56
+
57
+ Sub Sample()
58
+
59
+ Dim RE, strPattern As String, i As Long, msg As String, reMatch
60
+
61
+ Set RE = CreateObject("VBScript.RegExp")
62
+
63
+ strPattern = "*.(t|c|m)(a|s)(r|b|i)$"
64
+
65
+ With RE
66
+
67
+ .Pattern = strPattern
68
+
69
+ .IgnoreCase = True
70
+
71
+ .Global = True
72
+
73
+ For i = 1 To 10
74
+
75
+ Set reMatch = .Execute(Cells(i, 1))
76
+
77
+ If reMatch.Count > 0 Then
78
+
79
+ msg = msg & reMatch(0).Value & vbCrLf
80
+
81
+ End If
82
+
83
+ Next i
84
+
85
+ End With
86
+
87
+ MsgBox msg
88
+
89
+ Set reMatch = Nothing
90
+
91
+ Set RE = Nothing
92
+
93
+ End Sub
94
+
95
+
96
+
97
+ 上記のようなコードは,
98
+
99
+ エラーになります。
100
+
101
+ strPattern = "*.(t|c|m)(a|s)(r|b|i)$"
102
+
103
+ が構文としておかしいと考えているのですが,
104
+
105
+ 直し方がよくわかりません。