如何使用正则表达式验证以下字符串 - " 4500788390 14-AUG-2017" [英] How to validate following string using regular expression - "4500788390 14-AUG-2017"

查看:75
本文介绍了如何使用正则表达式验证以下字符串 - " 4500788390 14-AUG-2017"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用正则表达式验证

4500788390 2017年8月14日



我尝试过:



Plz描述您的努力将受到高度赞赏。谢谢

解决方案

尝试:

 ^ \d {1,10} \s + \ d\d-(JAN | FEB | MAR | APR | MAY | JUN | JUL | AUG | SEP | OCT | NOV | DEC)-\d {4} 

但是......这是一个坏主意。

使用正则表达式将其分成数字和日期部分:

 ^(?< Number> \d { 1  10 })\ s(? < Date> \d\d -...- \\\\\\\ n)


然后使用DateTime .TryParse或DateTime.TryParseExact来检查和转换日期。正则表达式不擅长验证日期信息 - 有太多例外!


Validate using Regular Expression
4500788390 14-AUG-2017

What I have tried:

Plz Describe your effort will be highly appreciated. Thanks

解决方案

Try:

^\d{1,10}\s+\d\d-(JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC)-\d{4}


But ... it's a bad idea.
Use a regex to split it into the number and date portions:

^(?<Number>\d{1,10})\s(?<Date>\d\d-...-\d\d\d\d)


And then use DateTime.TryParse or DateTime.TryParseExact to check and convert the date. Regexes are not good at verifying date info - there are too many exceptions!


这篇关于如何使用正则表达式验证以下字符串 - &quot; 4500788390 14-AUG-2017&quot;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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