regex - RegEx 用于识别后跟特殊模式的日期
问题描述
我有一个以不同间隔出现的字符串/值模式。模式如下: 30/09/2016 2,085,669 0 0 UC 否
- 日期>空格>逗号分隔的数字>空格>数字>空格>数字>空格>字符串>空格>数字
我如何识别它并从细胞中提取。我一直在尝试使用正则表达式来解决这个问题。请注意,该模式可以在单个单元格中的任何实例中出现。即。
- Somestring(空格)(30/09/2016 2,085,669 0 0 UC No)(空格) 更多字符串
- Somemorestring(空格)(2016 年 9 月 30 日 2,085,669 0 0 UC 否)
- 括号仅用于说明
为了确定日期,我使用了下面的正则表达式,这不是最好的方法,但可以完成我的工作。
(^\d{1,2}\/\d{1,2}\/\d{4}$)
如何用剩余的图案缝合这个?
解决方案
You are only matching the date like part between the anchors to assert the start ^
and the end $
of the string.
Note that if you only want to match the value you can omit the parenthesis ()
to make it a capturing group around the expression.
You could extend it to:
^\d{1,2}\/\d{1,2}\/\d{4} \d+(?:,\d+)+ \d+ \d+ [A-Za-z]+ [A-Za-z]+$
Explanation
^
Start of string\d{1,2}\/\d{1,2}\/\d{4}
Match date like pattern\d+(?:,\d+)+
Match 1+ digits and repeat 1+ times matching a comma and a digit\d+ \d+
Match two times 1+ digits followed by a space[A-Za-z]+ [A-Za-z]+
Match 2 times 1+ chars a-z followed by a space$
End of string
推荐阅读
- python - 如何使用 Google Drive API 计算(子)文件夹中的每个文件?
- node.js - 如何处理节点/快递中未知数量的参数
- aframe - 如何在附加到 gltf 元素的自定义组件内引用多种材料
- html - 如何将中间项目居中在列表中
- r - 删除为反应性数据框创建的 R 闪亮应用程序中的标记
- linux - java本机内存泄漏故障排除
- python - 为什么我不能将关键字参数传递给 list.index() 方法?
- python - UnicodeWarning: Unicode 相等比较失败
- informix - IBM Informix MacOS v-ids.12.10.FC9DE - 无法识别的选项
- javascript - 我无法设置按钮的背景颜色