Search MySQL database by regex (in reverse order)

If I have a database table that has one column containing a regular expression pattern, is it possible to return rows (without systematically testing each row in turn) so that the row matches?

for example, a table like this:

RowID     RegExPattern
1         foo\.$
2         bar\.$
3         baz\.$
4         (foo|bar)\.$

and the input line as follows:

foo.php

will return RowID 1and4

+5
source share
1 answer

If I have a database table in which there is one column containing a regular expression pattern, is it possible to return rows [...] so that the row matches?

Yes it is possible.

SELECT RowID
FROM yourtable
WHERE 'foo.php' REGEXP RegExPattern

Please note that your regular expressions do not match. If you omit $then they will be.

, : sqlfiddle

( )

Err... no. .

+7

All Articles