MySQL RegEx: Got error 'empty (sub)expression' from regexp [duplicate]

匿名 (未验证) 提交于 2019-12-03 01:08:02

问题:

This question already has an answer here:

I have a column participants which contains a value like "99005|99001|99002|99001999|99004" which are user logins.

What exactly I want is to match "99001" without matching "99001999".

Here is my method:

SELECT * FROM `bv_sklad_products` WHERE `stage`=4 AND `participants` REGEXP ('^([^\|]+(\|))*(99001|99005)((\|)[^\|]+)*$') AND `start_date` BETWEEN '2015-07-09' AND '2015-07-10' ORDER BY `id` DESC LIMIT 0,100 

And the error message I get:

Got error 'empty (sub)expression' from regexp 

What am I doing wrong?

回答1:

You may use word boundaries.

regexp  '[[:<:]]99001[[:>:]]' 

or

regexp '(^|[|])99001([|]|$)' 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!