2

我有一个正则表达式列表,并希望返回这些行,其中包含一个通过任何正则表达式的字段。反正有类似以下的东西:

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

在 EJBQL 中似乎根本不可能使用正则表达式,所以我猜我必须使用本机(MySQL)查询。

4

2 回答 2

2

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$)
于 2010-12-30T13:33:57.427 回答
1

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
于 2010-12-30T13:33:05.193 回答