下面是从短信内容提取日期的正则表达式,有时年份用的是两位,有时四位,月份也可能为1位或两位,日期也可能为1位或2位,下面的表达式如何改?
If e.DataCol.Name = "SmsBody" Then '短信内容
If e.DataRow.IsNull("SmsBody") Then ''短信内容是否为空
e.DataRow("会议时间") = Nothing '如果为空,则清除会议时间
Else
Dim str As String = e.DataRow("SmsBody")
Dim part As String = "\d{4}年\d{1,2}月\d{1,2}日"
If System.Text.RegularExpressions.Regex.Ismatch(str, "\d{4}年\d{1,2}月\d{1,2}日") = True Then
Dim mc As object = System.Text.RegularExpressions.Regex.Matches(str, "\d{4}年\d{1,2}月\d{1,2}日")
Dim rq As String = mc(0).value
Output.show(rq)
rq = rq.Replace("年","-").replace("月","-").replace("日","-").Trim("-")
Dim rq2 As Date
If Date.TryParse(rq, rq2) Then '如果转换成功
e.DataRow("会议时间") = rq2 ' Output.Show(d) '输出转换结果
Else
e.DataRow("会议时间") = Nothing 'Output.Show("无效日期格式") '给出错误提示
End If
End If
End If
End If