最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Regex to filter out everything but a certain date - Stack Overflow

programmeradmin2浏览0评论

How can I create a javascript function which would filter out everything but a certain date in DD.MM.YYYY format?

Example:

08.03.2012.
četvrtak, 8.3.2012. 14:25
Četvrtak, 08.03.2012 22:19
08.03.2012 13:13
08.03.2012 / 20:04
08.03.2012., 20:41
08.03.2012 19:02

everyone of these needs to return 08.03.2012

How can I create a javascript function which would filter out everything but a certain date in DD.MM.YYYY format?

Example:

08.03.2012.
četvrtak, 8.3.2012. 14:25
Četvrtak, 08.03.2012 22:19
08.03.2012 13:13
08.03.2012 / 20:04
08.03.2012., 20:41
08.03.2012 19:02

everyone of these needs to return 08.03.2012

Share Improve this question asked Mar 9, 2012 at 7:11 ttkalecttkalec 7411 gold badge7 silver badges26 bronze badges 0
Add a ment  | 

2 Answers 2

Reset to default 4

This actually could be better :)

/\b\d{1,2}\.\d{1,2}\.\d{4}\b/

Try this

\b\d{1,2}\.\d{1,2}\.\d{4}\b

See it here on Regexr

But this is checking only the format, not if this is a valid Date!

\b is a word boundary to avoid partial matches

\d is a digit

{n,m} is a quantifier, requiring a min of n and a max of m

发布评论

评论列表(0)

  1. 暂无评论