js REGEX | Get the last two sets of numbers in a string, How?


I have Strings in this format:




How do you get the last 2 sets of Numbers?

For example, in


I want to get:

07e8e2376d12e2d20a1e4c2159569c43_243_141599.jpg Only the Numbers in bold with the underscore in between them

Is it possible??.....

I tried: var getDigts = str.split('_'), //this way is ok but I have to split again the getDigts[2] as in str2.split(".") to get rid of the DOT.

Is there a workaround or something quicker than double split with plain REGEX? Thx


I tried to use str.match(/(\d+_\d+).jpg/)[1] as suggested by @Michael Best ... Just experienced a big ERROR: The reason is because am looping through each string to get the numbers... NOW, Should there be something like:

6b255c1c689e2e7ee88e6d5d8ab10e9b_307_17234.jpg 8b342878cb8d848608d422a2c02b5e32_7_240723.jpg 649ff5658ad274d8cee67b1f6d34600c_90_182456.png 07e8e2376d12e2d20a1e4c2159569c43_243_141599.jpg

Notice the: .png line. is there a REGEX to match both .jpg and/or .png at the same time?

I tried to remove the jpg from the .jpg something like: str.match(/(\d+_\d+)./)[1] but this fails when it comes to strings like: 07e8e2376d12e2d20a1e4c2159569c43_243_141599.jpg

it returns

07e8e2376d12e2d20a1e4c 2159569c43_243 _141599.jpg

instead of


Any Help is highly appreciated...

Here's a quick-and-dirty regex:

var nums = str.match(/(\d+_\d+)\.\w+$/)[1];