vba/excel 正規表現の使用
VBA/Excel で正規表現を利用する
参考資料
MSDNのサイト:
サンプルサイト:
事前準備/VBE側
参照設定は次の項目にチェックを入れておくこと:
作ったの(ソース)
標準モジュールに作成。
パターンに合致した場合と、合致しなかった場合で処理を分ける必要あるけど眠いのでいったんここまで(要確認)
この後どうしよう
Set mymatches = myre.Execute(mystring)
ソース
Function gethostname(xyz As String) '-------------------------- xtmp = "" Set myre = New RegExp With myre .Pattern = "^Logwatch for (.+) \(Linux\)$" .IgnoreCase = True End With mystring = xyz Set mymatches = myre.Execute(mystring) ' Cells(10, 12) = mystring xtmp = mymatches(0).SubMatches(0) '--- ' Cells(10, 11) = xtmp '--- Set myre = Nothing gethostname = xtmp End Function