MySQL provides REGEXP a.k.a. RLIKE for matching regular expressions.
How do I list the positions of the matches?
For instance, for a table with contents
X | Y
--------+---------------
abcd | abaab
efgh | ababbaaabaaaab
I would like to be able to write something that takes Y
and aa*b
as arguments and returns all matches of the regexp aa*b
in column Y
, like this:
X | POS | LEN
--------+-------+-------
abcd | 1 | 2
abcd | 2 | 2
efgh | 1 | 2
efgh | 3 | 2
efgh | 6 | 4
efgh | 10 | 5
How can this be done?
Thus far, the best I can think of is a dirty workaround: try matching every possible substring, like is done here, and based on that, generate multiple results, either by using a stored procedure, or by generating and executing INSERT statements.
Is there a saner way to do this?