Steven
Steven

Reputation: 18869

Getting a date from a string containing a date with jQuery

Basically, I have a string like this:

text text text text text 1/12/2012 text text text text

I need to somehow get that date out of the string. I'm terrible with regular expressions, and I was wondering if there's an easy way to get it with jQuery.

Upvotes: 1

Views: 72

Answers (1)

a'r
a'r

Reputation: 37009

You don't need jQuery for this, just use a regular expression, eg.

/\d{1,2}\/\d{1,2}\/\d{4}/.exec('text text 1/12/2012 text text')

Note, that this only extracts strings that look like a date and they may be invalid.

Upvotes: 6

Related Questions