I have the following rows of data:

> 
> login;visit\_homepage;buy
> 
> 
> register;login;buy;visit\_homepage
> 
> 
> 

I want to match all rows that have login event followed by buy event. There might be some other events between the login and buy events. Buy can be last event and login can be first event. I need exact match of login and buy not wildcard.

I have tried this:

`SELECT * FROM events WHERE events_list ~ 'login;.*buy;?.*$';`

but i think it does not cover all cases.

Thanks