你能帮我从字符串/文字中提取日期
假设我有以下字符串
"This is a date, January 23, 2016 Stackoverflow!"
"this 27 Aug 16 is in date format."
"03.22.2017 is also a date."
我需要的输出就是这个。
January 23, 2016
27 Aug 16
03.22.2017
基本上我在文中只需要的是日期。 请帮忙。感谢
答案 0 :(得分:1)
评论中共享的@PᴇʜRegex模式完全符合您的示例。以下是如何将其与单元格函数一起使用。
请勿忘记添加对“ Microsoft VBScript正则表达式5.5 ”的引用
The requested resource does not support http method 'PUT'.
输入位于A列,B列使用公式Function simpleCellRegex(Myrange As Range) As String
Dim regEx As New RegExp
Dim strPattern As String
Dim strInput As String
Dim strOutput As String
Dim matches As Object
strPattern = "(?:January|Februrary|March|April|May|June|July|August|September|October|November|December) [0-9]{1,2}, [0-9]{4}|[0-9]{1,2} (?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) [0-9]{2,4}|[0-9]{1,2}.[0-9]{1,2}.[0-9]{2,4}"
If strPattern <> "" Then
strInput = Myrange.Value
With regEx
.Global = True
.MultiLine = True
.IgnoreCase = False
.Pattern = strPattern
End With
If regEx.Test(strInput) Then
Set matches = regEx.Execute(strInput)
If matches.Count <> 0 Then simpleCellRegex = matches.Item(0)
Else
simpleCellRegex = "Not matched"
End If
End If
End Function
<强>测试强>