groovy / java正则表达式检查是否“yyyy.MM.dd”格式 [英] groovy/java regex check if "yyyy.MM.dd" format

查看:663
本文介绍了groovy / java正则表达式检查是否“yyyy.MM.dd”格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表示日期的字符串,例如2010.12.25。如何控制是否为yyyy.MM.dd格式?没有必要检查日期的有效性。

I have a string representing a date, for example "2010.12.25". How can I control if it is of "yyyy.MM.dd" format? There is no need to check the validness of the date.

推荐答案

你有正则表达式,在Groovy中,你可以做:

You have the Regex, in Groovy, you can just do:

boolean match = "2010.12.12" ==~ /\d{4}\.\d{2}\.\d{2}/

这篇关于groovy / java正则表达式检查是否“yyyy.MM.dd”格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆