You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用Google App Script从邮箱地址中提取用户名

提取邮箱中的用户名

可以用JavaScript的split()方法分割邮箱字符串,以@为分隔符,取分割后的第一个元素就能得到@左侧的用户名。

修改后的脚本如下:

function getEmail() {
  var userEmail = Session.getActiveUser().getEmail();
  // 分割邮箱字符串,提取@左侧的用户名
  var username = userEmail.split('@')[0];
  Logger.log(username);
}

说明:

  • split('@')会将邮箱字符串拆分为数组,例如"username@domain.com"分割后会变成["username", "domain.com"]
  • 取数组下标为0的元素,就是@左侧的用户名
  • 最终通过Logger.log()输出提取到的用户名

内容的提问来源于stack exchange,提问作者d-ron

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.29 10:12:08