Reputation: 699
I'm tryin to match any string containing STORE when it's NOT followed by HOUSE. I looked at this answer Postgres Regex Negative Lookahead but cannot get it to work with my example.
Here is the sql demo and below is my code:
CREATE TABLE table1
(s character varying)
;
INSERT INTO table1
(s)
VALUES
('FROM THE STORE TO THE HOUSE AND'),
('FROM THE HOUSE TO THE STORE AND')
;
select * from table1 where s ~ '(STORE)(?!HOUSE)';
UPDATE Had wrong link for SQL demo - it is fixed now
Upvotes: 2
Views: 379
Reputation: 91508
Your regex matches STORE
only if it is not immediatly followed by HOUSE
.
I guess you want:
(STORE)((?!HOUSE).)*$
This will match STORE
in the second row of your example.
Upvotes: 3