提取特定格式的电子邮件地址的函数

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

Function to pull email addresses in a specific format

问题

数据集如下:

V1023897@gmail.com
E3028753@gmail.com

格式为1个字符后跟7个数字值。

不太清楚从哪个函数开始。非常感谢任何帮助!谢谢!

英文:

The data set looks like this:

V1023897@gmail.com
E3028753@gmail.com

The format is 1 character followed by 7 numerical values.

Little lost on what function to start off with. Any help is greatly appreciated and thank you!

答案1

得分: 1

你要翻译的内容如下:

"你正在尝试执行的操作称为“模式匹配”,在 SQL Server 中,它是在 WHERE 子句中使用运算符 LIKE 来执行的。

如果您预先知道您的列包含电子邮件,您想从中获取具有以下格式的电子邮件:

  • 一个字母
  • 七个数字
  • @
  • 域名

您可以使用以下代码:

SELECT * 
FROM emails
WHERE email LIKE '[A-Za-z][0-9][0-9][0-9][0-9][0-9][0-9][0-9]@%'

模式解释

  • [A-Za-z]:A-Z 或 a-z 范围内的字符
  • [0-9]:0-9 范围内的数字
  • ...
  • @:@ 字符
  • %:任何其他字符序列

输出

email
V1023897@gmail.com
E3028753@gmail.com

在此处查看演示 here

英文:

The operation you're attempting to do is called "pattern matching", and in SQL Server it's carried out with the operator LIKE inside the WHERE clause.

If you know in advance that your column contains emails, from which you want to take the ones having the format:

  • one letter
  • seven numbers
  • @
  • domain

you can use the following code:

SELECT * 
FROM emails
WHERE email LIKE '[A-Za-z][0-9][0-9][0-9][0-9][0-9][0-9][0-9]@%'

Pattern Explanation:

  • [A-Za-z]: a character in range A-Z or a-z
  • [0-9]: a number in range 0-9
  • ...
  • @: @ character
  • %: any other sequence of characters

Output:

email
V1023897@gmail.com
E3028753@gmail.com

Check the demo here.

huangapple
  • 本文由 发表于 2023年5月26日 00:19:41
  • 转载请务必保留本文链接:https://go.coder-hub.com/76334393.html
匿名

发表评论

匿名网友

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

确定