Here is my issue, let's say I have a few strings with a number in the string, or not, and then a year, or range of years at the end of the string. I need to be able to match the year, or range of years at the end but not the numbers in the string. Here's an example of what I mean
var str = 'CO2 emissions per capita 1990-2010'; //when run here I should get 1990-2010
var str2 = 'GHG emissions with LUCF 2010'; // when run from here I should get 2010
I have gotten really close a couple of times but my problem is I am either match the 2 in CO2 with the years, or in other strings there might be a () in it and that gets matched as well. Here are the regexs I have tried so far.
var numRegex = /([\d-_\s])+$/;
var noTextRegex = /([^a-zA-Z\s]+)/;
var parts = numRegex.exec(str); //this matches the 2 in CO2
var partsTry2 = noTextRegex.exec(str); //this matches the 2 in CO2 as well but also matches () in other strings.
I have never really been too good with regex, it has always eluded me. Any help would be greatly appreciated. Thank you