Public Function 正则表达式A(f As String) As Date
'2023-02-06 1653830
If New Regex("\d{4}.\d{2}.\d{2}.\d{6}").IsMatch(f) Then
Dim nian = Strings.Mid(f, 1, 4)
Dim yue = Strings.Mid(f, 6, 2)
Dim ri = Strings.Mid(f, 9, 2)
Dim shi = Strings.Mid(f, 12, 2)
Dim feng = Strings.Mid(f, 14, 2)
Dim miao = Strings.Mid(f, 16, 2)
Return New Date(nian, yue, ri, shi, feng, miao)
End If
Return Nothing
End Function
Public Function 正则表达式B(f As String) As Date
'IMG_20190924_182424
'VID_20190924_182424
'MVIMG_20190924_182424
If New Regex("(?:IMG|VID|MVIMG).20\d{6}.\d{6}").IsMatch(f) Then
If Strings.Left(f, 5) = "MVIMG" Then
f = Strings.Replace(f, "MVIMG", "AAA")
End If
Dim nian = Strings.Mid(f, 5, 4)
Dim yue = Strings.Mid(f, 9, 2)
Dim ri = Strings.Mid(f, 11, 2)
Dim shi = Strings.Mid(f, 14, 2)
Dim feng = Strings.Mid(f, 16, 2)
Dim miao = Strings.Mid(f, 18, 2)
Return New Date(nian, yue, ri, shi, feng, miao)
End If
Return Nothing
End Function
Public Function 正则表达式C(f As String) As Date
'微信文件的时间戳
'mmexport1522311367525
If New Regex("mmexport1\d{12}").IsMatch(f) Then
Dim startTime = TimeZone.CurrentTimeZone.ToLocalTime(New System.DateTime(1970, 1, 1))
Dim time = Strings.Mid(f, 9, 13)
Return startTime.AddMilliseconds(time)
End If
Return Nothing
End Function
Public Function 正则表达式D(f As String) As Date
'好像是小米的时间解析
'Screenshot_2023-03-13-18-46-44-425_com.tencent.wework
If New Regex("Screenshot_20\d{2}.\d{2}.\d{2}.\d{2}.\d{2}.\d{2}").IsMatch(f) Then
f = Strings.Replace(f, "Screenshot_", "")
'2023-03-13-18-46-44-425_com.tencent.wework
Dim nian = Strings.Mid(f, 1, 4)
Dim yue = Strings.Mid(f, 6, 2)
Dim ri = Strings.Mid(f, 9, 2)
Dim shi = Strings.Mid(f, 12, 2)
Dim feng = Strings.Mid(f, 15, 2)
Dim miao = 0
Return New Date(nian, yue, ri, shi, feng, miao)
End If
Return Nothing
End Function
Dim str = 文件名
Dim reta = 正则表达式A(Str)
If reta <> Nothing Then
i.正则表达式匹配结果 = "命中A方案"
i.解析的时间 = reta
Continue For
End If
reta = 正则表达式B(str)
If reta <> Nothing Then
i.正则表达式匹配结果 = "命中B方案"
i.解析的时间 = reta
Continue For
End If
reta = 正则表达式C(str)
If reta <> Nothing Then
i.正则表达式匹配结果 = "命中C方案"
i.解析的时间 = reta
Continue For
End If
reta = 正则表达式D(str)
If reta <> Nothing Then
i.正则表达式匹配结果 = "命中D方案"
i.解析的时间 = reta
Continue For
End If