有没有人对是否/如何创建正则表达式来匹配任何给定时间段内的日期有任何想法?
两个例子:
23/11/2008 - 12/04/2010
//The expression would evaluate whether 16/04/2010 was in this range, and return false.
//The expression would determine whether 03/12/2009 was in this range, and return true.
和
01/09/1984 - 30/04/2001
//The expression would evaluate whether 16/04/1990 was in this range, and return true.
//The expression would determine whether 03/12/2009 was in this range, and return false.
我一直在绞尽脑汁思考如何想出一些办法,但我一无所获。网络上的示例只对检查日期是否采用特定格式感兴趣,而对验证范围无关。
我在这里标记 C# 的原因是,这不能在直接正则表达式中完成,并且需要为每个单独的案例手动构建范围正则表达式。
最佳答案
将字符串解析为 DateTime
并进行比较不是更容易吗?
关于c# - 匹配日期范围的正则表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1460398/