从电子邮件前言中提取最多一定数量的字母数字字符

huangapple go评论62阅读模式
英文:

I want to extract up to a specific number of alphanumeric characters from an email preamble

问题

我正在尝试提取电子邮件前言中最多前10个字母数字字符(0-9,a-z,A-Z)(不包括所有特殊字符)。提取应在“@”之前停止。

示例,功能应如下:

john@yahoo.com : john
suzieQ87@hotmail.com: suzieQ87
ilikemakingeggseverymorning@gmail.com: ilikemakin
49!Gar.a_ge8UT@aol.com: 49Garage8U

我想在Google Sheets中使用正则表达式。

谢谢!

我尝试过:

=regexextract("alwayssa.turning@gmail.com","^.{0,9}[[:alpha:]]") 返回:alwayssa.tu
=regexextract("suzie@gmail.com",".{0,9}[\w\s^@]") 返回:suzie@gmai
=REGEXEXTRACT("suzie40@gmail.com,".{0,9}[\w\d^\W]") 返回:suzie40@gm

我无法弄清如何排除特殊字符以及如何在“@”处停止。

英文:

I'm trying to extract up to the first 10 alphanumeric characters (0-9, a-z, A-Z) (exclude all special characters) from email preambles. The extraction should stop exclusive of the "@".

Examples, How it should function:

john@yahoo.com : john
suzieQ87@hotmail.com: suzieQ87
ilikemakingeggseverymorning@gmail.com: ilikemakin
49!Gar.a_ge8UT@aol.com: 49Garage8U

I would like to use regex in Google Sheets.

Thanks!

I tried:

=regexextract("alwayssa.turning@gmail.com","^.{0,9}[[:alpha:]]") returned: alwayssa.tu
=regexextract("suzie@gmail.com",".{0,9}[\w\s^@]") returned: suzie@gmai
=REGEXEXTRACT("suzie40@gmail.com,".{0,9}[\w\d^\W]") returned: suzie40@gm

I can't figure out how to exclude special characters and how to stop at the "@".

答案1

得分: 1

Sure, here are the translated code parts:

由于您想跳过特殊符号,您可以分为两步进行提取:
- 替换特殊符号:
`REGEXREPLACE(A1,"[^a-zA-Z0-9@]+","")`
- 使用正则表达式提取最多前十个符号:
`[[:alnum:]]{0,10}`

```markdown
=REGEXEXTRACT(REGEXREPLACE(A1,"[^a-zA-Z0-9@]+",""),"[[::alnum::]]{0,10}")

Is there anything else you need?

英文:

Since you want to skip special symbols, you can do extraction in two steps:

  • replace special symbols:
    REGEXREPLACE(A1,"[^a-zA-Z0-9@]+","")
  • extract up to ten first symbols with regex:
    [[:alnum:]]{0,10}
=REGEXEXTRACT(REGEXREPLACE(A1,"[^a-zA-Z0-9@]+",""),"[[:alnum:]]{0,10}")

huangapple
  • 本文由 发表于 2023年4月11日 00:58:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/75979041.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定