Regular expressions in postgresql
I have a table that contains the following three rows
name
----------------------------------------------
user - help center test 4 [120,2010-08-19]
test - help center test 2 [123,2010-01-19]
help center test [20109,2010-01-01]
(3 rows)
Now i need to get a exact match of "help center test" thus it should开发者_如何学Go return the 3rd row. I basically need to do this exact match as if [20109,2010-01-01] does not exist in help center test [20109,2010-01-01] thus eliminating the brackets and everything within the brackets. NOte the result within the bracket could be anything.
If the brackets weren't there I would use something like
SELECT name FROM clients WHERE lower(name) like '%call center test%'
and that would give me the result but now I need to do the same with the above results? Is this possible?
According to: http://www.postgresql.org/docs/8.1/static/functions-matching.html :
SELECT name FROM clients WHERE name ~* 'help center test \\[.*?\\]'
Just to clarify that the ~* is a case insensitive match, so there's no need for the lower() function call on the name. This will match all rows that start "help center test [" then have n characters and finally end with "]" (both without double quotes, of course).
精彩评论