views:

62

answers:

1

Hi!

At the moment, I am coding an Google Chrome extension (in Javascript) which interfaces with GMail. The extension needs to know the unique email identifier that is present at the end of every GMail URL.

Eg. https://mail.google.com/mail/#inbox/11a4ac0cg2bc3330 https://mail.google.com/mail/#label/Archived+Emails/11a4c8b472b03c87

What would be the best way to get this unique identifier using Javascript (through regex or otherwise, preferably in a function like this:

function getIdentifier(URL){ [Insert your magic here] return ID; }

Thanks,

DLiKS

+2  A: 

this is based on your samples provided, if you're assured of the format, you can use .substirng() and .lastIndexOf(), like this:

function getIdentifier(URL){
  return URL.substring(URL.lastIndexOf('/') + 1);
}

You can give it a try here, this keeps it pretty simple, find the last /, move over one to exclude the / itself, take the rest of the string.

Nick Craver
Why didn't I think of this?! Thanks a lot!
DLiKS