[英]Regex to validate week and year
I want to validate a string with this pattern: ww/yyyy. 我想使用以下模式验证字符串:ww / yyyy。
With: ^([0-9]{4})
, I check if the year has 4 digits. 使用:
^([0-9]{4})
,我检查年份是否有4位数字。
I tried to put these two regex together without success. 我试图将这两个正则表达式放在一起,但没有成功。
(5[0-3]|[1-4][0-9]|0[1-9])/^([0-9]{4})
^
means the start of a line or the start of the string (depends on options on the regex implementation.) So try this: ^
表示行的开头或字符串的开头(取决于regex实现的选项。)因此,请尝试以下操作:
^(5[0-3]|[1-4][0-9]|0[1-9])/([0-9]{4})$
$
means the end of the line or end of the string. $
表示行的结尾或字符串的结尾。
If you don't include ^
and $
in the pattern, something like this will get matched: foo20/2000bar
. 如果在模式中不包含
^
和$
,则将匹配以下内容: foo20/2000bar
。
How about other way, though both mean same: 其他方式如何,尽管两者含义相同:
^((0[1-9]|[1-4][0-9]|5[0123])/([0-9]{4}))$
Thanks for your time 谢谢你的时间
(5[0-3]|[1-4][0-9]|0[1-9])/([0-9]{4})
为什么需要^
字符?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.