Postgres Regular Expression Query
Postgres documentation regarding pattern matching
For the most part, is a normal regular expression. The only tricky thing is that back slashes \
have to be escaped \\
.
SELECT DISTINCT personid, personname
FROM s2_keycards
WHERE descname='Access granted'
AND personid ~ '^[A-Z]{1,5}\\d{2,4}-(\\d){1,6}$'
AND ndt LIKE '2016-07%'
ORDER BY personid;