开发者

EJBQL/MySQL Regexes and IN

I have a list of Regexes and want to return those rows with a field which passes any reg开发者_运维知识库ex. Is there anyway to something like the following:

SELECT * FROM Foo as f WHERE f.bar IN ("regex1","regex2");

It doesn't look like Regexes are possible at all in EJBQL so I'm guessing I have to use a native (MySQL) query.


Why not combine the regexes into one?

"(?:" + regex1 + ")|(?:" + regex2 + ")"

So if regex1 = "^.*foo(.*)bar" and regex2 = "baz(.*)frob$", you'd get

(?:^.*foo(.*)bar)|(?:baz(.*)frob$)


No, this is not possible. At least not the way you think it is.

Do this instead: Insert the regexes as rows into a table. Then query

SELECT 
  * 
FROM
  Foo AS f
  INNER JOIN Regexes AS re ON f.bar REGEXP re.pattern
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜