ここは新しく、RegExの新機能です。私は正規表現を使用して、この形式の文字列を日付05-18-16または5-18-16または05 18 16または5 18 16をYYYY MM DD形式に変換しようとしています。RegEx MM DD YYYYからYYYY MM DD
文字列内の日付は、YYまたはYYYYであることに注意してください。
「検索」式は機能していますが、置換に問題があります。私は私が仕事だろうと思ったこのサイト上のいくつかのコードを見つけましたが、結果は常に「1900年1 31」で、2016年05 18" は
Sub StackExPost()
Dim strIn As String, strReturn As String
strIn = "Test 05 09 16 and 5-9-2016 Test"
strReturn = fcnRegEx(strIn, "\b(0?[1-9]|1[0-12])(|-)(0?[1-9]|[1-2][0-9]|3[0-1])(|-)((?:\d{4}|\d{2}))", "$5 $3 $1")
MsgBox strReturn 'I get get and transpose the components.
strReturn = fcnRegEx(strIn, "\b(0?[1-9]|1[0-12])(|-)(0?[1-9]|[1-2][0-9]|3[0-1])(|-)((?:\d{4}|\d{2}))", Format("$5", "YYYY") & " " & Format("$2", "MM") & " " & Format("$1", "DD"))
MsgBox strReturn '... but can't apply the formatting.
End Sub
Function fcnRegEx(strIn As String, strPattern As String, Optional strReplace As String = vbNullString, Optional bGlobal As Boolean = True)
Dim objRegex As Object
Dim objRegM As Object
Set objRegex = CreateObject("vbscript.regexp")
objRegex.Global = bGlobal
With objRegex
.IgnoreCase = True
.Pattern = strPattern
If .Test(strIn) Then
Set objRegM = .Execute(strIn)
If strReplace = vbNullString Then
fcnRegEx = objRegM(0).Value 'submatches(0)
Else
fcnRegEx = objRegex.Replace(strIn, strReplace)
End If
Else
fcnRegEx = "//No Match\\"
End If
End With
lbl_Exit:
Exit Function
End Function
は読書のためと提供された指導ありがとうございましたではない。
と交換してください?これはexcelとかvbaだと思われるので、unix時にはセルのフォーマットを設定するだけです。 – Andreas