I have an SQL query that returns all companies records ignore the ones with email matching a given pattern using Postgresql (info+random_name@example.com) the plus sign is included as well.
Normal email pattern would be ‘random_name@example.com’
My SQL query looks like:
SELECT * from companies
where email !~ E'^(info)+[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+[.][A-Za-z]+';
Does the syntax look correct?
Update:
The following query does match the pattern:
SELECT * from companies
where email ~ E'^(info\+)+[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+[.][A-Za-z]+';
Now how to reverse it, as !~ doesn’t seem to ignore the matching pattern
update2:
Correct syntax is indeed the following:
SELECT * from companies
where email ~ E'^info\\+[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+[.][A-Za-z]+';
Escape (double escape) the plus sign:
Moreover, there’re no need to make a group with
(info)