Search code examples
javascriptregexgreasemonkey

REGEX to get ID ath the end of an URL without /


I'm trying to do a GreaseMonkey script and i'm stucked on a REGEX to get the ID of an article in URL.

I have URL like https://www.blabla.com/poney-2000-poneys-dance-bla,272317

And i want to use the ID at the end after the Comma : 272317

I tried this REGEX : (,([\d]+)) to avoid taking digit in the rest of the URL and it get me ,272317 but I want it without the comma at the begining.

Do you have an idea how i can improve my REGEX ?

Thanks a lot :)


Solution

  • An alternative approach without regex:

    var url = 'https://www.blabla.com/poney-2000-poneys-dance-bla,272317';
    url.substring(url.lastIndexOf(',') + 1);
    

    The regex would be (\d+)$ to lookup the digits in the end but it doesn't consider the comma.