mbrc
mbrc

Reputation: 3983

MSSQL regex to detect if email starts with number.number

I would like to exclude spam mails. Normally spam mails has [email protected]

How can i check in MSSQL if mail has this syntax. Somehow with regex?

SELECT * FROM mytable WHERE mycolumn REGEXP "^.*[^0-9][0-9]{2}$";

Upvotes: 0

Views: 197

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1271231

I think your description of what a spam email looks like may be a bit outdated. But, if you want to exclude such emails in SQL Server, you can -- with a bit of effort.

SQL Server does not support regular expressions, but it does support an enhanced like. So, you can do:

where email not like '%.%.%@%' or
      email not like '%[^0-9]%.%.%@$' or
      email not like '%.%[^0-9]%.%@$'

This implements three conditions:

  • The base email name does not have three parts
  • The first part of the base email name has a non-digit
  • The second part of the base email name has a non-digit

Combined, these are equivalent to your condition.

Upvotes: 1

Related Questions