Reputation: 3657
var str = "7-Dec-1985"
var str = "12-Jan-1703"
var str = "18-Feb-1999"
How would I got about pulling just the year out of the string? I have tried a number of different RegExp but none seem to be working.
I would have expected re = new RegExp(/(\d+)\D*\z/);
To have worked but sadly it did not.
Any suggestions would be very appreciated
Upvotes: 7
Views: 26793
Reputation: 429
I'd try: /.*(\d{4})$/
Test your regex's here: http://www.regular-expressions.info/javascriptexample.html
Upvotes: 3
Reputation: 19081
Since all of your str
(s) use -
as a separator, this will work for you:
var str = "7-Dec-1985",
arr = str.split('-'),
year = arr[2];
console.log(year);
Upvotes: 16