1.参照設定

Grep(RegEXP)を使用する場合は次のライブラリーの参照設定が必要です。
Microsoft VBScript Regular Expressions 5.5
参照設定参照。

2.サンプル

次のFunctionはGrepのパターンGrep_Patternに従って、入力文字列がパターンに合っているかを検証する例です。
例の場合「E01B0927」だとTrueになります。

  '宣言部でGrepのパターンを設定します。以下はパターンの説明です
  'Set RegExp Pattern
  '0-  ^ --------------------------- Start of regular expression
  '1-  (E|X) ----------------------- 1 digit for E or X
  '2-3 (\d{2}) --------------------- 2 digits for 00 - 99    ← 波括弧{ }を使用します。
  '4-  ([A-N]) --------------------- 1 digit for Alphabet of A - N    ← 角括弧[ ]を使用します。
  '5-6 ([0[1-9]|1[0-2]) ------------ 2 digits for Month(01-12}
  '7-8 (0[1-9]|[12][0-9]|3[01]) ---- 2 digits for day(01-31)
  '0-  $ --------------------------- End of regular expression

  Public Const Grep_Pattern  As String = "^(E|X)(\d{2})([A-N])(0[1-9]|1[0-2])(0[1-9]|[12][0-9]|3[01])$"

Function example801_Validate(strSerial As String) As Boolean
  Dim RegEx As VBScript_RegExp_55.RegEXP
   
  Set RegEx = New VBScript_RegExp_55.RegEXP

  With RegEx
    .MultiLine = False
    .Global = False
    .IgnoreCase = False
    .Pattern = Grep_Pattern         '←Grepのパターン
  End With
  
  example801_Validate = RegEx.Test(strSerial)
  Set RegEx = Nothing

End Function

最終更新のRSS
Last-modified: 2014-03-11 (火) 01:58:42 (3693d)