10

I'd need to have a regular expression so that I can find all invalid email addresses in our database table.

SELECT *
FROM dbo.[Users] AS u 
WHERE u.EmailAddress not like 'regular expression of valid email addresses'

Does SQL Server support regular expressions? If so, how could I write one for email address?

7

1 Answer 1

13

T-SQL does not support regular expressions. You can however create a .net CLR function that will add this ability.

This might help.
http://www.simple-talk.com/sql/t-sql-programming/clr-assembly-regex-functions-for-sql-server-by-example/

Sign up to request clarification or add additional context in comments.

6 Comments

thanks but we have so much restriction here and we can't install assemblies into the sql server engine.
You had me there for a minute, but reading the link it looks like that will only work for the find/replace dialog in management studio, not a as part of a query :(
Unfortunately the topic given is about SQL Server MS rather then SQL Server engine itself
It looks like that RegEx support relates to SSMS, not to TSQL
That SQL 2012 link is just talking about regexes in SSMS -- not anything new built into SQL Server. William, if you can't install assemblies you are not going to be able to use regexes. You'll have to roll your own as best you can using SQL Server's intrinsic string functions.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.