开发者

MySQL regular expression to exclude a certain literal at the beginning of a string?

开发者 https://www.devze.com 2023-04-11 00:27 出处:网络
I\'d like to match all \"X joined your network\" strings, X being any arbitrary string except when starting with \"RE:\". So I\'d like to exclude \"RE: X joined your network\" type of strings.

I'd like to match all "X joined your network" strings, X being any arbitrary string except when starting with "RE:". So I'd like to exclude "RE: X joined your network" type of strings.

I tried

^[^R][^E][^.:.].+ joined your network$

and

^[^.RE:.].+ joined your network$

and

^[^(RE\\:)].+ joined your network$

but none of these seem to be correct (using MySQL 5.1 with latin1 charset). 开发者_如何学运维What is the correct expression for this?


You need

SELECT * FROM table WHERE 
    table.field NOT LIKE "RE:%" AND table.field LIKE "%joined your network"

MySQL is not case sensitive so you'll catch RE: Re: and re:


The below query will help you to retrieve all your results from the table.

Here, I'm using REGEXP expression in the query for matching the pattern.

As we know that MySQL is case insensitive, so RE is the same as re.

SELECT * FROM table_name 
WHERE column_name NOT REGEXP '^[RE]' 
AND 
column_name REGEXP '(joined your network)$';
0

精彩评论

暂无评论...
验证码 换一张
取 消