Regular expression that only finds last instance
Posted on 2016-09-09
If I have strings such as these:
2. AB 123
4. AB 123-1
5. AB XYZ-1
I need a regular expression that determine if the end contains /\-\d+$/ and only #3, #4, and #5 to qualify.
The problem I'm running into is that the above regex matches for #1, #3, #4, and #5 since they all have hyphens.
var splitter = str.split(/\-\d+$/)
I just don't have a good way to tell if the string qualifies with /\-\d+$/ when there are possible hyphen instances earlier in the string.