dthhlf1777 2013-09-15 03:56
浏览 23
已采纳

如何使用正则表达式选择日期[关闭]

in the sentence :

 Effectuées le    : 06/09/2013 15:12:30

Could you help me please to select only 06/09/2013? Thank you

edit: I'm using dftotext php function to extract some files and I should match the date that is always written in thios way (regex+php)

edit2: I have tried :

(?<=es le    :)(.*)

But it takes all date+ time I would select only date http://www.rubular.com/r/6qmGKIAn00

  • 写回答

2条回答 默认 最新

  • dougu2036 2013-09-15 04:15
    关注

    The .* will match everything after the :, including the space and the time. To get just the date, be more specific than a wildcard that matches any character. Use this pattern:

    #(\d{2}/\d{2}/\d{4})#
    

    Capture group #1 will contain the date.

    You tagged it as only regex and not php, but in PHP that would be:

    preg_match('#(\d{2}/\d{2}/\d{4})#', $string_containing_the_sentence)
    

    and the date will be assigned to $1.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛