获取时间字符串

php_wsd 2007-05-14 01:50:47
<%
str="2007-01-01 12:12:12 问题 1234"
'str="sdfd 2007-01-01 12:12:12 问题"
'str="2007-01-01 12:12sdfdf"
'str="a 2007-01-01 sdddd"
%>

在asp中,如何用正则表达式来获取以上字符串是的时间字符串?
...全文
155 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
lovefm105 2007-05-14
  • 打赏
  • 举报
回复
看不明白你写的是什么???
duwa789 2007-05-14
  • 打赏
  • 举报
回复
str = "2007-01-01 12:12:12 问题 1234"
patrn = "\d{4}[-][0,1]{1}\d{1}[-][0-3]{1}\d{1}"

Function RegExpTest(patrn, strng)
Dim regEx, Match, Matches ' 建立变量。
Set regEx = New RegExp ' 建立正则表达式。
regEx.Pattern = patrn ' 设置模式。
regEx.IgnoreCase = True ' 设置是否区分大小写。
regEx.Global = True ' 设置全局替换。
Set Matches = regEx.Execute(strng) ' 执行搜索。
For Each Match in Matches ' 遍历 Matches 集合。
RetStr = RetStr & "Match " & I & " found at position "
RetStr = RetStr & Match.FirstIndex & ". Match Value is '"
RetStr = RetStr & Match.Value & "'." & vbCRLF
Next
RegExpTest = RetStr
End Function


Response.Write(RegExpTest("\d{4}[-][0,1]{1}\d{1}[-][0-3]{1}\d{1}",str))
php_wsd 2007-05-14
  • 打赏
  • 举报
回复
那三个不可以,因为时间的格式会变化的,如
2007-01-02
2007-02-03 12:12:12
02-05 12:12
等多种,直接用left,right,mid来获取不容易得到。
createyuan 2007-05-14
  • 打赏
  • 举报
回复
我是菜鸟……
呵,好像可以用left mid right 可以获取吧

28,391

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧