regex - Trying to separate the year month and day fields via RegEx
问题描述
I have a series of dates that I am trying to separate into years, months and days. These dates are in the yyyy-mm-dd format. I'm not very familiar with RegEx, but I have tried (\dddd)\-(\dd)\-(\dd)
.
Any help is appreciated.
解决方案
接受的答案也将匹配无效日期,如 1234-56-78,或者如果 mm 和 dd 位于错误的位置。
([1-2][0-9]{3})\-([0-1][0-9])\-([0-3][0-9])
做更多的验证。
推荐阅读
- javascript - 使用 ng-if 或 ng-show 根据用户输入显示部分
- r - 根据数据框列条件更新 For 循环外的向量
- scala - 如何从 Kotlin 调用 Scala 密封特征?
- python - 访问 xarray DataArray 中的单个元素
- html - 设置 nativeElement.scrollTop 不起作用,滚动到 div 的底部
- php - 如何使用 codeigniter 进行日期之间的查询?
- rdf - 无法获取输出 (OWL) 文件中的所有值
- javascript - 如何使用 ytdl-core 通过 Discord.js 机器人发送下载的 .mp3?
- spring - 带有 Kotlin 的 Spring Boot - @Value 注释未按预期工作
- c# - 如何从 WindowsService 获取当前用户配置文件位置