【问题标题】:Get Unique Email Identifier from GMail URL从 GMail URL 获取唯一的电子邮件标识符
【发布时间】:2011-03-26 22:32:06
【问题描述】:

目前,我正在编写一个与 GMail 交互的 Google Chrome 扩展程序(使用 Javascript)。扩展程序需要知道每个 GMail URL 末尾存在的唯一电子邮件标识符。

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

使用 Javascript 获取此唯一标识符的最佳方法是什么(通过正则表达式或其他方式,最好是在这样的函数中:

函数 getIdentifier(URL){ [在这里插入你的魔法] 返回标识; }

谢谢,

DLiKS

【问题讨论】:

    标签: javascript regex gmail


    【解决方案1】:

    这是基于您提供的示例,如果您确定格式,您可以使用.substirng() 和.lastIndexOf(),如下所示:

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

    You can give it a try here,这让它很简单,找到最后一个/,移到一个以排除/本身,取出字符串的其余部分。

    【讨论】:

    • 我怎么没想到?!非常感谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-11-15
    • 1970-01-01
    • 1970-01-01
    • 2016-03-29
    • 2012-08-03
    • 1970-01-01
    • 2018-11-03
    相关资源
    最近更新 更多