问题
I am doing some basic text matching in Postgres 9.3.5.0.
Here is my code so far:
Select text from eightks
WHERE other_events = true and
keywordRegexs = [\y(director and member \s+ and resigned)\y/ix];
I am getting the following errors
psql:test3.sql:3: invalid command \y(director psql:test3.sql:5: ERROR: syntax error at or near "[" LINE 3: keywordRegexs = [
I am trying to find documents which contain those exact phrases.
回答1:
The regular expression match operator in Postgres is ~.
The case insensitive variant is ~*.
Branches are enclosed in ().
SELECT text
FROM eightks
WHERE other_events = true
AND keywordregexs ~* '(\y(director | member \s+ |resigned)\y)';
The meaning of "those exact phrases" is not clear in the question.
Details in the manual.
来源:https://stackoverflow.com/questions/25779596/regex-and-textmatching-issue