0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

テスト109

Posted at

Sub reg_test2()

'正規表現練習
Dim reg As Object
Dim str1 As String
Dim aaa As Variant
Dim aa As Variant

str1 = "今日は令和11年2月11日です"
Set reg = CreateObject("VBScript.RegExp")

'和暦だけ取得
With reg
    .Pattern = "(昭和|平成|令和)(\d{1,2})年(\d{1,2})月(\d{1,2})日"   'パターンを指定
    .IgnoreCase = True       '大文字と小文字を区別する(False)、しない(True)
    .Global = True           '文字列全体を検索する(True)、しない(False)
End With

Set aaa = reg.Execute(str1)

Debug.Print aaa.Item(0)

'-------------------------------------------
str1 = "今日は2024/11/21です"

'YYYY/M/D(YYYY/MM/DD)だけ取得
With reg
    .Pattern = "(\d{4})/(\d{1,2})/(\d{1,2})"   'パターンを指定
    .IgnoreCase = True       '大文字と小文字を区別する(False)、しない(True)
    .Global = True           '文字列全体を検索する(True)、しない(False)
End With

Set aaa = reg.Execute(str1)

Debug.Print aaa.Item(0)

'-------------------------------------------
str1 = "今日は2024年11月21日です"

'YYYY年M月D日(YYYY年MM月DD日)だけ取得
With reg
    .Pattern = "(\d{4})年(\d{1,2})月(\d{1,2})日"   'パターンを指定
    .IgnoreCase = True       '大文字と小文字を区別する(False)、しない(True)
    .Global = True           '文字列全体を検索する(True)、しない(False)
End With

Set aaa = reg.Execute(str1)

Debug.Print aaa.Item(0)
Set reg = Nothing


End Sub
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?