英文:
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}")
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论