Sunday, June 2, 2024
 Popular · Latest · Hot · Upcoming
60
rated 0 times [  65] [ 5]  / answers: 1 / hits: 23078  / 13 Years ago, tue, december 6, 2011, 12:00:00

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


More From » regex

 Answers
215

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);

[#88710] Monday, December 5, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
sandra

Total Points: 708
Total Questions: 100
Total Answers: 84

Location: Bosnia and Herzegovina
Member since Thu, Jun 24, 2021
3 Years ago
sandra questions
Tue, Jun 30, 20, 00:00, 4 Years ago
Sun, May 31, 20, 00:00, 4 Years ago
Wed, May 20, 20, 00:00, 4 Years ago
Fri, May 31, 19, 00:00, 5 Years ago
;