1
我試圖用VB6正則表達式與捕獲組來解析和重新排列的字符串:VB6正則表達式匹配的日期需要調整
Dim innfilename As String
Dim outfilename As String
innfilename = "4.6.12.Jack&DianeWedding004.jpg"
outfilename = innfilename
Dim regexB As RegExp
Dim regexBMatchCol As MatchCollection
Dim regexBMatch As Match
Set regexB = New RegExp
regexB.IgnoreCase = True
regexB.Global = True
regexB.Pattern = "^(\d{1,2})\.(\d{1,2})\.(\d{2,4})\.(.*)$"
Set regexBMatchCol = regexB.Execute(innfilename)
If regexBMatchCol.Count > 0 Then
Set regexBMatch = regexBMatchCol(0)
mnth = regexBMatch.SubMatches(0)
dayy = regexBMatch.SubMatches(1)
year = regexBMatch.SubMatches(2)
remd = regexBMatch.SubMatches(3)
yearInt = Val(year)
mnthInt = Val(mnth)
dayyInt = Val(dayy)
If yearInt >= 70 And yearInt <= 99 Then
year = "19" & year
Else
year = "20" & year
End If
If mnthInt >= 1 And mnthInt <= 9 Then
mnth = "0" & mnth
End If
If dayyInt >= 1 And dayyInt <= 9 Then
dayy = "0" & dayy
End If
outfilename = year & "." & mnth & "." & dayy & "." & remd
End If
,但我的正則表達式不即工作regexBMatchCol.Count捲起被零。 任何人都可以發現我的錯誤?
TIA,
還是學習史蒂夫
在VB6,如果我想創建一個只是一個反斜槓的字符串,我需要通過'「\\」'或者'「\」'來工作嗎?如果前者,那麼你的正則表達式中的反斜槓需要逃脫VB6。 – 2012-03-06 05:19:57
這看起來應該工作 - 你使用哪個Regex庫? – 2012-03-06 05:47:27