ttkalec
ttkalec

Reputation: 741

Regex to filter out everything but a certain date

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

Upvotes: 0

Views: 2566

Answers (2)

WTK
WTK

Reputation: 16981

This actually could be better :)

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

Upvotes: 4

stema
stema

Reputation: 93086

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

Upvotes: 4

Related Questions