Luka Luka - 1 year ago 92
MySQL Question

MySQL - select rows via patterns

Take the following


| id | pattern |
| 0 | date in {int} day|days|week|weeks|month|months|year|years |

As you can see, the mock-up pattern in row
expects the third word to be an integer and the fourth word to match one within the stated collection.

How would I go about selecting rows, given an inputted sentence, that matches some type of regular expression residing in the
field (similar to how I expressed above), eg.

select * from patterns where match(pattern, 'date in 25 weeks');

# result - row with id: 0


Answer Source

You can rewrite your patterns in regular expressions and then build a query this way:

SELECT * FROM patterns WHERE 'date in 25 weeks' REGEXP pattern;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download