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
re = new RegExp(/(\d+)\D*\z/);is actually creating two regex objects, the first being/(\d+)\D*\z/which is then passed to theRegExpcontstructor. Normally you would usenew RegExponly if you have the need construct the pattern dynamically which you would then pass as a string to the constructor. In all other casesre = /(\d+)\D*\z/;is perfectly ok.