是否有更有效的方法来生成日期的REGEX字符串
Is there a more efficient way to generate a REGEX String for Dates
我正在为QT项目寻找一个更高效的正则表达式。
以下正则表达式匹配的日期字符串:
8 June 2009
2009-06-08
1/31/1971
ca. 1971
circa 1971
about 1971
abt 1971
before 1971
bef 1971
bante 1971
after 1971
aft 1971
apost 1971
between 1970 and 2000
bet 1970 and 2000
btw 1970 and 2000
1970-2000
from 1970 to 2000
est 2000
2000 or 2001
2000 | 2001
2019
1.10.2019
June 2009
6/2019
表达式:
^((?:Jan|January|Feb|February|Mar|March|Apr|April|May|May|Jun|June|Jul|July|Aug|August|Sep|September|Oct|October|Nov|November|Dec|December)[t ]+[0-9]{4})|^((?:3[01]|[12][0-9]|0?[1-9])[t ]+(?:Jan|January|Feb|February|Mar|March|Apr|April|May|May|Jun|June|Jul|July|Aug|August|Sep|September|Oct|October|Nov|November|Dec|December)[t ]+[0-9]{4})|^([0-9]{4} or [0-9]{4})|(^(?:1[0-2]|0?[1-9])[/.-][0-9]{4})|(^[0-9]{4}-[0-9]{4})|(^from[t ]+[0-9]{4}[t ]+to[t ]+[0-9]{4})|(^btw[t ]+[0-9]{4}[t ]+and[t ]+[0-9]{4})|(^between[t ]+[0-9]{4}[t ]+and[t ]+[0-9]{4})|(^[tnvfr ]*([0-9]{4})$)|(^[0-9]{4}[t ]+|[t ]+[0-9]{4}b)|(^(?:1[0-2]|0?[1-9])[/.-](?:3[01]|[12][0-9]|0?[1-9])[/.-][0-9]{4})|(^est[t ]+[0-9]{4})|(^after[t ]+[0-9]{4})|(^before[t ]+[0-9]{4})|(^bef[t ]+[0-9]{4})|(^abt[t ]+[0-9]{4})|(^about[t ]+[0-9]{4})|(^circa[t ]+[0-9]{4})|(^ca[^nr][t ]+[0-9]{4})|(^bante[t ]+[0-9]{4})|(^aft[t ]+[0-9]{4})|(^apost[t ]+[0-9]{4})|(^btw[t ]+[0-9]{4}[t ]+and[t ]+[0-9]{4})|(^bet[t ]+[0-9]{4}[t ]+and[t ]+[0-9]{4})|(^[0-9]{4}-(?:1[0-2]|0?[1-9])-(?:3[01]|[12][0-9]|0?[1-9]))
验证结果匹配https://rubular.com/r/boBqo3h0KBt7oARubularRebex
我能找到的唯一解决方案是使用交替组执行。这是匹配字符串日期列表的合理方法吗?
提前感谢!
我将提交RegEx作为发布和目标集中的RegEx,作为必要的额外检查。谢谢你的评论。
相关文章:
- 查询SQLite数据库中的日期
- 获取日期异步信号安全吗?如果在信号处理程序中使用,它会导致死锁吗
- 此模式的C++RegEx
- Log4cpp:以UTC/GMT时区打印日期
- 使用C++的日期库读取时间
- 日期格式为C++
- 如何在 C++20 计时中为日期添加天数?
- 如何在QTableView中排序和更改日期格式
- 如何在cpp中使用地图显示给定日期范围内(在下面的问题中)的费率?
- Gtkmm 会不断检查 Gtk::日历上的所选日期是否发生变化
- C++ std::regex 使用前瞻失败
- fmt 与 Howard Hinnant 的日期:为什么从 fmt::to_string "{}"?FMT 和日期的最佳实践?
- 使程序检查当前日期是否=预期日期
- std::regex:匹配由数字和空格组成的字符串,并提取数字.如何?
- 如何找到两个日期之间的时间差异(以秒和纳秒为单位)?
- JNI 日期值转换问题,在C++中获取不同的长整型值
- 确定夏令时是否适用于特定日期
- C++日期库因时区而失败
- 是否有更有效的方法来生成日期的REGEX字符串
- c++ boost regex日期错误