日期:2014-05-16  浏览次数:20669 次

给出一个字符串,如何在数据表中查询与之匹配的正则表达式?
在一个数据表中存有许多不同的正则表达式,简单如下

aid regex

1 [a-f4-9]*
2 abcd(.*)
3 sd(f+)dac
4 (.+?)698d


给定一个字符串,如ecd87addc,应该如何写sql语句,才能在该表中查询与这个字符串匹配的正则表达式?或者有没有更好的解决方法?望高手不吝赐教!

------解决方案--------------------
select * from t_table where 1= 'ecd87addc ' regexp aidregex
------解决方案--------------------
------ ----------------------------------------
table1 CREATE TABLE `table1` (
`aidregex` char(20) NOT NULL,
PRIMARY KEY (`aidregex`)
) ENGINE=InnoDB DEFAULT CHARSET=gb2312
------ ----------------------------------------
select * from table1 where '1cd87addc ' REGEXP aidregex;
------ ----------------------------------------

query result(1 records)
aidregex
1[a-f4-9]*