开发者

MySQL regexp list

I have a MySQL table with column regexp and column value like:

regexp    value
 ab+c      abc
 bc+d      bcd

Also I开发者_如何学运维 have a list of values like: (not in database, its in query)

abc
abbc
bcccccd

I need to match the values in the list to the regexps and get the values for each item - expected output:

match    value
 abc      abc
 abbc     abc
bcccccd   bcd

If this wasn't a regexp I could use

select `regexp`, `value`
from `mytable`
where `regexp` in ('abc', 'abbc', 'bcccccd')

But I can't use this to match regexp. Even if there is some sort of regexp in this will still be problematic because it will return the regexp and not the value that matched - unwanted output:

regexp    value
 ab+c      abc
 ab+c      abc
 bc+d      bcd


Maybe you can do something like:

select rt.value from regextable as rt where 'bcccccd' rlike rt.regexp

And use one query per input value.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜